From 32ad67c5b1563dba667bf6c9980e56db61f6bcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Mon, 18 Oct 2021 10:50:36 +0200 Subject: [PATCH] Upgrade hintable to v1.6 (#905) --- .github/workflows/test-unit.yml | 4 ++-- composer.json | 5 +++-- phpstan.neon.dist | 3 --- src/Model.php | 35 ++++++++++++++++----------------- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 680a3327e..a28266d6e 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -48,7 +48,7 @@ jobs: run: | if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpunit/phpunit johnkary/phpunit-speedtrap phpunit/phpcov --dev; fi if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer --dev && composer --no-interaction --no-update require jdorn/sql-formatter; fi - if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan --dev; fi + if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/* --dev; fi composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader - name: "Run tests: SQLite (only for Phpunit)" @@ -144,7 +144,7 @@ jobs: run: | if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "Phpunit Lowest" ] && [ "${{ matrix.type }}" != "Phpunit Burn" ]; then composer remove --no-interaction --no-update phpunit/phpunit johnkary/phpunit-speedtrap phpunit/phpcov --dev; fi if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer --dev && composer --no-update --ansi --prefer-dist --no-interaction --no-progress require jdorn/sql-formatter; fi - if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan --dev; fi + if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/* --dev; fi composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader if [ "${{ matrix.type }}" == "Phpunit Lowest" ]; then composer update --ansi --prefer-dist --prefer-lowest --prefer-stable --no-interaction --no-progress --optimize-autoloader; fi if [ "${{ matrix.type }}" == "Phpunit Burn" ]; then sed -i 's~ *public function runBare(): void~public function runBare(): void { gc_collect_cycles(); gc_collect_cycles(); $memDiffs = array_fill(0, '"$(if [ \"$GITHUB_EVENT_NAME\" == \"schedule\" ]; then echo 64; else echo 4; fi)"', 0); for ($i = -1; $i < count($memDiffs); ++$i) { $this->_runBare(); gc_collect_cycles(); gc_collect_cycles(); $mem = memory_get_usage(); if ($i !== -1) { $memDiffs[$i] = $mem - $memPrev; } $memPrev = $mem; rsort($memDiffs); if (array_sum($memDiffs) >= 4096 * 1024 || $memDiffs[2] > 0) { $this->onNotSuccessfulTest(new AssertionFailedError( "Memory leak detected! (" . implode(" + ", array_map(fn ($v) => number_format($v / 1024, 3, ".", " "), array_filter($memDiffs))) . " KB, " . ($i + 2) . " iterations)" )); } } } private function _runBare(): void~' vendor/phpunit/phpunit/src/Framework/TestCase.php && cat vendor/phpunit/phpunit/src/Framework/TestCase.php | grep '_runBare('; fi diff --git a/composer.json b/composer.json index 560f048e1..509a60204 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "ext-pdo": "*", "atk4/core": "dev-develop", "doctrine/dbal": "^2.13.3 || ^3.0", - "mvorisek/atk4-hintable": "~1.5.0" + "mvorisek/atk4-hintable": "~1.6.0" }, "require-release": { "php": ">=7.4 <8.2", @@ -47,12 +47,13 @@ "ext-pdo": "*", "atk4/core": "~3.1.0", "doctrine/dbal": "^2.13.3 || ^3.0", - "mvorisek/atk4-hintable": "~1.5.0" + "mvorisek/atk4-hintable": "~1.6.0" }, "require-dev": { "ergebnis/composer-normalize": "^2.13", "friendsofphp/php-cs-fixer": "^3.0", "johnkary/phpunit-speedtrap": "^3.3", + "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^0.12.82", "phpunit/phpcov": "*", "phpunit/phpunit": "^9.5.5" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9019d98ea..7326c89db 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,6 +1,3 @@ -includes: - - vendor/mvorisek/atk4-hintable/phpstan-ext.neon - parameters: level: 6 paths: diff --git a/src/Model.php b/src/Model.php index 0f8815b4e..8f810d71a 100644 --- a/src/Model.php +++ b/src/Model.php @@ -553,6 +553,23 @@ public function add(object $obj, array $defaults = []): object return $this->_add($obj, $defaults); } + /** @var array */ + protected $fieldSeedByType = []; + + /** + * Given a field seed, return a field object. + */ + public function fieldFactory(array $seed = null): Field + { + $seed = Factory::mergeSeeds( + $seed, + isset($seed['type']) ? ($this->fieldSeedByType[$seed['type']] ?? null) : null, + $this->_default_seed_addField + ); + + return Field::fromSeed($seed); + } + /** * Adds new field into model. * @@ -571,24 +588,6 @@ public function addField(string $name, $seed = []): Field return $this->_addIntoCollection($name, $field, 'fields'); } - /** - * Given a field seed, return a field object. - */ - public function fieldFactory(array $seed = null): Field - { - $seed = Factory::mergeSeeds( - $seed, - isset($seed['type']) ? ($this->fieldSeedByType[$seed['type']] ?? null) : null, - $this->_default_seed_addField - ); - - return Field::fromSeed($seed); - } - - /** @var array */ - protected $fieldSeedByType = [ - ]; - /** * Adds multiple fields into model. *