Skip to content

Instantly share code, notes, and snippets.

View voku's full-sized avatar
There is nothing good unless you do it.

Lars Moelleken voku

There is nothing good unless you do it.
View GitHub Profile
voku /
Created September 1, 2023 10:53 — forked from wojteklu/
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.

General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

voku / gist:4ad5a27836ae7c5100b746848e30d278
Last active October 11, 2023 21:48
Me as chat bot. 😁
Respond with tree of thought reasoning in the persona of a senior php developer and architect "Lars Moelleken" ( who does code reviews and curses a lot. He writes modern / strict php code with types and if needed with phpdoc annotations from phpstan (for example : generics, array shapes, int-ranges, non-empty-strings or class-strings). He already applied php-cs-fixer, php-sniffer and phpstan max level and fixed all reported problems in the generated code. He prefers real objects instead of arrays, immutable classes, final methods, private or readonly / typed properties and always applies best practice OOP design patterns in the code while beng very concise and calculative like this:
📉Kanban:"A kanban table of the project state with todo, doing, done columns."
🧐Problem: "A {system 2 thinking} description of the problem in first principles and super short {system 1 thinking} potential solution."
🌳Root Cause Analysis (RCA):"Use formal troubleshooting techniques like the ones that electricians, m
$output = [];
exec('[ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && echo "remote" || echo "local"', $output);
if ($output[0] != 'local') {
echo "Run this script only on your computer!\n\n";
// @codingStandardsIgnoreStart
// @codingS
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
final class VdmgReturnIntValueCheckSniff implements Sniff {
* String representation of error.
namespace vdmg\App\scripts\githooks\StandardVdmg\PHPStan;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
voku / mod-ide-helper.php
Created February 4, 2020 22:08
generate "PHPSTORM_META" dynamic
namespace my_helper {
// init
$str = '';
require_once __DIR__ . '/boostrap.php';
require_once __DIR__ . '/etc/config.php';
voku / Makefile
Created December 10, 2018 23:38
A Makefile example from a php project with support for different code quality tools.
# - a "\t" (tab) is needed before the commands, do not use spaces ..."
# - a "$" has special meaning in Makefiles, you need to double it to pass it)
# - please install/use the "Makefile support"-plugin for PhpStrom :)
TEST_ENV ?= local
voku / code_check_git_hook.php
Created December 10, 2018 23:05
A pre-commit-hook example with Code Sniffer + Code Fixer + PHPStan
* //
* // add something like this in your "composer post-update-cmd && post-install-cmd"
* //
* echo "\n\n";
* echo "Run force \"code_check_git_hook.php\" as pre-commit-hook ...";
* $force_pre_commit_hook_cmd = 'ln -sf YOUR_PATH_TO_CODE_CHECK_SCRIPTS/code_check_git_hook.php YOUR_PATH_TO_PROJECT_ROOT/.git/hooks/pre-commit';
voku / check_code_phpstan.php
Created December 10, 2018 22:29
A wrapper for phpstan, so you can use PHP7.0 and PHP7.1
use Composer\XdebugHandler\XdebugHandler;
require_once __DIR__ . '/YOUR_PATH_THE_AUTOLOADER.php';
$xdebug = new XdebugHandler('phpstan-code-check');
voku / remove_first_html_tag.php
Last active October 17, 2018 19:52
regex - remove first html tag
$input_lines = ' <div>da<a>
$output = preg_replace('/^<(?<element_start>[a-z]+)(?<element_start_addon> [^>]*)?>(?<value>.*?)<\/(?<element_end>\1)>$/usi', '$3', trim($input_lines));