Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade hintable to v1.6 #905

Merged
merged 2 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@
"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",
"ext-intl": "*",
"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"
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
includes:
- vendor/mvorisek/atk4-hintable/phpstan-ext.neon

parameters:
level: 6
paths:
Expand Down
35 changes: 17 additions & 18 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,23 @@ public function add(object $obj, array $defaults = []): object
return $this->_add($obj, $defaults);
}

/** @var array<string, 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.
*
Expand All @@ -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<string, array> */
protected $fieldSeedByType = [
];

/**
* Adds multiple fields into model.
*
Expand Down