Pint and Larastan - pre-commit hooks

Adding laravel/pint and nunomaduro/larastan into your Laravel project using composer with --dev prefix. For both tools, we need to have configuration files, pint.json and phpstan.neon.dist in order to work. The minimal configuration for pint would look like: { "preset": "laravel" } And for larastan, following configuration is recommended: includes: - ./vendor/nunomaduro/larastan/extension.neon parameters: paths: - app/ # Level 9 is the highest level level: 5 Once added, we need to place the following bash script into ....

July 12, 2023 · 1 min · anvyst

Composer require/replace: package necromancy

Once in a while, I get lucky being asked to revive some legacy client project, that needs massive upgrades. Normally, the upgrade goes fine, meeting all required upgrades, making sure all the functionality is in place. But this time, the project was so outdated that the packages listed in composer dependencies didn’t just get into the archive. They were moved to a different repository, then closed down, and then mirrored by another developer....

April 14, 2020 · 1 min · anvyst

PHP RFC: Comprehensions

Another interesting RFC recently landed to PHP community. So far the easiest way of explaining comprehensions for me comes from Python world: Comprehensions are constructs that allow sequences to be built from other sequences. Here’re some examples from List comprehensions in Python: def palindromes(strings): return [s + s[::-1] for s in strings] def starting_with(letter, names): return [name for name in names if name[0].lower() == letter.lower()] JavaScript, however, decided to remove its support from standard in favour of filter/arrow/map functions....

April 13, 2019 · 1 min · anvyst

CakePHP Time formatting: year of "week of year"

While jumping between PHP and JavaScript - one of the most annoying things is dates handling. Recently, one of the clients reported that, while using our app for appointments and work schedule - they lost one of the working days. Client’s worker was supposed to work on the 31st of December 2019. Firstly, working on the 31st is an achievement. Since we can’t affect it, “bug report” was filled on our end....

December 7, 2018 · 1 min · anvyst

Psalm - static analysis of PHP

Once every blue moon, I dive into Github repositories to check for something useful for my everyday routines. This time, I stumbled upon Psalm from Vimeo. Psalm is designed to understand that complexity, allowing it to quickly find common programmer errors like null references and misspelled variable names. vimeo Psalm documentation I’ve been using phpstan for basic code static analysis for a while. I was running it with various rule levels, depending on the complexity of the codebase....

October 9, 2018 · 1 min · anvyst

CakePHP CsvMigrations: prototype in 3 2 .. Done!

Every programmer is tired of coding yet another login form. Yet another CRUD view module. So today I’ll show you an example where our laziness can get you building prototype systems without a single line of extra code. One of the tasks, that we had to face when developing Qobrix CRM, was fast prototyping of the system. The result of ultimate laziness and DRY concept resulted in cakephp-csv-migrations plugin that we try to use pretty much everywhere, while delivering the system....

February 2, 2018 · 4 min · anvyst

CakePHP: Interview with Larry E. Masters

Interesting interview with one of the core members of CakePHP community - Larry E. Masters. Throughout the interview Larry covers CakePHP Framework history, as well as covering major milestones of CakePHP 3.x version. If you’re still into 2.x then it’s time to upgrade, as it brings some nice perks. More flexible code, and massive performance boost.

May 29, 2017 · 1 min · anvyst

PHP: Testing protected methods in CakePHP3

One of the things I recently had to deal with - PHP unit testing protected methods of the class in CakePHP 3. Few seconds of checking StackOverflow brought a nice and elegant way of checking protected methods using ReflectionClasses. Sebastian Bergmann has a complete guide how to check non-public functionality of the classes in his archieves. Here’s a short sample of the code using CakePHP3: <?php use Search\Model\Table\SaveSearchTable; use Cake\TestSuite\TestCase; class SaveSearchTableTest extends TestCase { public function setUp() { $this->SavedSearches = \Cake\ORM\TableRegistry::get('SavedSearches'); } public function testProtectedMethod() { $methodName = 'protectedMethod'; $reflectionClass = new \ReflectionClass('\Search\Model\Table\SaveSearchesTable'); $method = $reflectionClass->getMethod($methodName); $methodResult = $method->invokeArgs( $this->SavedSearches, ['arg1', ['arg2']]); $this->assertNotEmpty($methodResult); } }

February 7, 2017 · 1 min · anvyst

WP-CLI becomes part of make.wordpress.org

WP-CLI reached 1.x stable release. WordPress decided to make it as part of make.wordpress.org tools. Great news from the WordPress community and those who spends most of their time in the console. No more weird sftpd/vsftpd installations. It might come handy with composer bundle as we do it in Qobo for WordPress project templates. New home for WP-CLI docs https://t.co/oZleP9HwRX — WP-CLI (@wpcli) January 26, 2017

January 27, 2017 · 1 min · anvyst

PSR-7: storage-less sessions

The new session system was implemented by @srgmrzv using PSR-7 storage-less sessions: https://t.co/W6q2lm1Ryj https://t.co/fZFTrPuy3q — Matthieu Napoli (@matthieunapoli) January 26, 2017

January 27, 2017 · 1 min · anvyst