Skip to content

Commit

Permalink
Add dynamic return type seed support
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Dec 22, 2022
1 parent 4f3c851 commit d7ed918
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 84 deletions.
31 changes: 31 additions & 0 deletions phpstan-ext.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
services:
# move to atk4/core later (or at least atk4/data)
-
factory: Mvorisek\Atk4\Hintable\Phpstan\SeedDmrtExtension(Atk4\Core\Factory, factory, 0)
tags:
- phpstan.broker.dynamicStaticMethodReturnTypeExtension

-
factory: Mvorisek\Atk4\Hintable\Phpstan\SeedDmrtExtension(Atk4\Ui\AbstractView, add, 0)
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
factory: Mvorisek\Atk4\Hintable\Phpstan\SeedDmrtExtension(Atk4\Ui\Columns, addColumn, 0)
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
factory: Mvorisek\Atk4\Hintable\Phpstan\SeedDmrtExtension(Atk4\Ui\Form, addControl, 1)
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
factory: Mvorisek\Atk4\Hintable\Phpstan\SeedDmrtExtension(Atk4\Ui\Form, controlFactory, 1)
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
factory: Mvorisek\Atk4\Hintable\Phpstan\SeedDmrtExtension(Atk4\Ui\Grid, addColumn, 1)
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
-
factory: Mvorisek\Atk4\Hintable\Phpstan\SeedDmrtExtension(Atk4\Ui\Table, addColumn, 1)
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
90 changes: 10 additions & 80 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
includes:
- phar://phpstan.phar/conf/bleedingEdge.neon
# remove once https://github.com/phpstan/extension-installer/issues/36 is fixed
- phpstan-ext.neon

parameters:
level: 6
Expand Down Expand Up @@ -38,10 +40,13 @@ parameters:
message: '~^Call to an undefined method Atk4\\Ui\\View::addFields\(\)\.$~'
-
path: 'demos/form-control/calendar.php'
message: '~^Call to an undefined method Atk4\\Ui\\Form\\Control::addAction\(\)\.$~'
message: '~^Call to an undefined method Atk4\\Ui\\JsExpression::setDate\(\)\.$~'
-
path: 'demos/form-control/calendar.php'
message: '~^Call to an undefined method Atk4\\Ui\\JsExpression::open\(\)\.$~'
-
path: 'demos/form-control/calendar.php'
message: '~^Call to an undefined method Atk4\\Ui\\Form\\Control::getJsInstance\(\)\.$~'
message: '~^Call to an undefined method Atk4\\Ui\\JsExpression::clear\(\)\.$~'
-
path: 'demos/form-control/input2.php'
message: '~^Call to an undefined method Atk4\\Ui\\Form\\Control::onDelete\(\)\.$~'
Expand All @@ -51,21 +56,6 @@ parameters:
-
path: 'demos/form-control/multiline.php'
message: '~^Call to an undefined method Atk4\\Ui\\Form\\Layout::addColumn\(\)\.$~'
-
path: 'demos/form-control/upload.php'
message: '~^Call to an undefined method Atk4\\Ui\\Form\\Control::onDelete\(\)\.$~'
-
path: 'demos/form-control/upload.php'
message: '~^Call to an undefined method Atk4\\Ui\\Form\\Control::clearThumbnail\(\)\.$~'
-
path: 'demos/form-control/upload.php'
message: '~^Call to an undefined method Atk4\\Ui\\Form\\Control::onUpload\(\)\.$~'
-
path: 'demos/form-control/upload.php'
message: '~^Call to an undefined method Atk4\\Ui\\Form\\Control::setThumbnailSrc\(\)\.$~'
-
path: 'demos/form-control/upload.php'
message: '~^Call to an undefined method Atk4\\Ui\\Form\\Control::setFileId\(\)\.$~'
-
path: 'demos/form/form-section-accordion.php'
message: '~^Call to an undefined method Atk4\\Ui\\Form\\Layout::addSection\(\)\.$~'
Expand Down Expand Up @@ -117,30 +107,15 @@ parameters:
-
path: 'demos/interactive/wizard.php'
message: '~^Access to an undefined property Atk4\\Ui\\Form\\Control::\$placeholder\.$~'
-
path: 'src/CardDeck.php'
message: '~^Access to an undefined property Atk4\\Ui\\AbstractView::\$reload\.$~'
-
path: 'src/CardDeck.php'
message: '~^Access to an undefined property Atk4\\Ui\\AbstractView::\$queryArg\.$~'
-
path: 'src/CardDeck.php'
message: '~^Access to an undefined property Atk4\\Ui\\AbstractView&Atk4\\Ui\\UserAction\\ExecutorInterface::\$jsSuccess\.$~'
-
path: 'src/CardDeck.php'
message: '~^Call to an undefined method Atk4\\Ui\\AbstractView::addClass\(\)\.$~'
-
path: 'src/CardDeck.php'
message: '~^Call to an undefined method Atk4\\Ui\\AbstractView::on\(\)\.$~'
-
path: 'src/CardDeck.php'
message: '~^Call to an undefined method Atk4\\Ui\\AbstractView&Atk4\\Ui\\UserAction\\ExecutorInterface::onHook\(\)\.$~'
-
path: 'src/Crud.php'
message: '~^Call to an undefined method Atk4\\Ui\\UserAction\\JsExecutorInterface::stickyGet\(\)\.$~'
-
path: 'src/Form.php'
message: '~^Call to an undefined method Atk4\\Ui\\AbstractView::addButton\(\)\.$~'
-
path: 'src/Form.php'
message: '~^Call to an undefined method Atk4\\Ui\\Js\\JsChain::preventFormLeave\(\)\.$~'
Expand All @@ -159,9 +134,6 @@ parameters:
-
path: 'src/Js/JsVueService.php'
message: '~^Call to an undefined method Atk4\\Ui\\Js\\JsChain::createVue\(\)\.$~'
-
path: 'src/Menu.php'
message: '~^Call to an undefined method Atk4\\Ui\\AbstractView::setElement\(\)\.$~'
-
path: 'src/Menu.php'
message: '~^Call to an undefined method Atk4\\Ui\\AbstractView::addClass\(\)\.$~'
Expand Down Expand Up @@ -190,9 +162,6 @@ parameters:
path: 'src/SessionTrait.php'
count: 4
message: '~^Access to an undefined property Atk4\\Ui\\Tests\\SessionAbstractMock::\$name\.$~'
-
path: 'src/Table/Column.php'
message: '~^Call to an undefined method Atk4\\Ui\\AbstractView::setHoverable\(\)\.$~'
-
path: 'src/Table/Column.php'
message: '~^Call to an undefined method Atk4\\Ui\\JsCallback::onSelectItem\(\)\.$~'
Expand Down Expand Up @@ -264,9 +233,6 @@ parameters:

# TODO these rules are generated, this ignores should be fixed in the code
# for level = 3
-
path: 'src/Card.php'
message: '~^Method Atk4\\Ui\\Card::addButton\(\) should return Atk4\\Ui\\View\ but returns Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/CardDeck.php'
message: '~^Property Atk4\\Ui\\CardDeck::\$container \(Atk4\\Ui\\View\|null\) does not accept default value of type array<int\|string, string>\.$~'
Expand All @@ -276,63 +242,27 @@ parameters:
-
path: 'src/CardDeck.php'
message: '~^Property Atk4\\Ui\\CardDeck::\$paginator \(Atk4\\Ui\\Paginator\|false\|null\) does not accept default value of type array\{''Atk4\\\\Ui\\\\Paginator''\}\.$~'
-
path: 'src/CardDeck.php'
message: '~^Property Atk4\\Ui\\CardDeck::\$container \(Atk4\\Ui\\View\|null\) does not accept Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/CardDeck.php'
message: '~^Property Atk4\\Ui\\CardDeck::\$menu \(array\|false\|null\) does not accept Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/CardDeck.php'
message: '~^Property Atk4\\Ui\\CardDeck::\$search \(array\|Atk4\\Ui\\VueComponent\\ItemSearch\|false\) does not accept Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/CardDeck.php'
message: '~^Property Atk4\\Ui\\CardDeck::\$paginator \(Atk4\\Ui\\Paginator\|false\|null\) does not accept Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Form/AbstractLayout.php'
message: '~^Method Atk4\\Ui\\Form\\AbstractLayout::_addControl\(\) should return Atk4\\Ui\\Form\\Control but returns Atk4\\Ui\\View\.$~'
-
path: 'src/Form/Layout.php'
message: '~^Method Atk4\\Ui\\Form\\Layout::addButton\(\) should return Atk4\\Ui\\Button but returns Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Form/Layout.php'
message: '~^Method Atk4\\Ui\\Form\\Layout::_addControl\(\) should return Atk4\\Ui\\Form\\Control but returns Atk4\\Ui\\View\.$~'
-
path: 'src/Form/Layout.php'
message: '~^Method Atk4\\Ui\\Form\\Layout::addSubLayout\(\) should return Atk4\\Ui\\Form\\Layout but returns Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Form/Layout/Custom.php'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Custom::addButton\(\) should return Atk4\\Ui\\Button but returns Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Form/Layout/Section.php'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Section::addSection\(\) should return Atk4\\Ui\\Form\\Layout but returns Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Form/Layout/Section/Accordion.php'
message: '~^Return type \(Atk4\\Ui\\Form\\Layout\) of method Atk4\\Ui\\Form\\Layout\\Section\\Accordion::addSection\(\) should be compatible with return type \(Atk4\\Ui\\AccordionSection\) of method Atk4\\Ui\\Accordion::addSection\(\)$~'
-
path: 'src/Form/Layout/Section/Accordion.php'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Accordion::addSection\(\) should return Atk4\\Ui\\Form\\Layout but returns Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Form/Layout/Section/Tabs.php'
message: '~^Method Atk4\\Ui\\Form\\Layout\\Section\\Tabs::addTab\(\) should return Atk4\\Ui\\Form\\Layout but returns Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Grid.php'
message: '~^Property Atk4\\Ui\\Grid::\$menu \(Atk4\\Ui\\Menu\|false\) does not accept Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Grid.php'
message: '~^Property Atk4\\Ui\\Grid::\$paginator \(Atk4\\Ui\\Paginator\|false\) does not accept Atk4\\Ui\\AbstractView\.$~'
-
path: 'src/Grid.php'
message: '~^Property Atk4\\Ui\\Grid::\$paginator \(Atk4\\Ui\\Paginator\|false\) does not accept null\.$~'
-
path: 'src/Grid.php'
message: '~^Property Atk4\\Ui\\Grid::\$actionButtons \(Atk4\\Ui\\Table\\Column\\ActionButtons\|null\) does not accept Atk4\\Ui\\Table\\Column\.$~'
-
path: 'src/Grid.php'
message: '~^Property Atk4\\Ui\\Grid::\$selection \(Atk4\\Ui\\Table\\Column\\Checkbox\) does not accept Atk4\\Ui\\Table\\Column\.$~'
-
path: 'src/Grid.php'
message: '~^Method Atk4\\Ui\\Grid::addSelection\(\) should return Atk4\\Ui\\Table\\Column\\Checkbox but returns Atk4\\Ui\\Table\\Column\.$~'
-
path: 'src/Header.php'
message: '~^Property Atk4\\Ui\\Header::\$icon \(string\) does not accept Atk4\\Ui\\Icon\.$~'
Expand Down Expand Up @@ -375,6 +305,9 @@ parameters:

# TODO these rules are generated, this ignores should be fixed in the code
# for level = 5
-
path: 'src/Form.php'
message: '~^Parameter #2 \$value of method Atk4\\Ui\\View::setAttr\(\) expects string\|null, int given\.$~'
-
path: 'src/Form/Layout/Section.php'
message: '~^Parameter #1 \$object of method Atk4\\Ui\\View::add\(\) expects Atk4\\Ui\\AbstractView, array<int\|string, Atk4\\Ui\\Form\|class-string<Atk4\\Ui\\Form\\Layout>> given\.$~'
Expand Down Expand Up @@ -405,6 +338,3 @@ parameters:
-
path: 'src/Panel/Right.php'
message: '~^Parameter #1 \$object of method Atk4\\Ui\\App::add\(\) expects Atk4\\Ui\\AbstractView, array given\.$~'
-
path: 'src/Popup.php'
message: '~^Parameter #1 \$view of method Atk4\\Ui\\Callback::terminateJson\(\) expects Atk4\\Ui\\View, Atk4\\Ui\\AbstractView given\.$~'
2 changes: 1 addition & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public function initLayout($seed)
$this->html->invokeInit();
}

$this->layout = $this->html->add($layout); // @phpstan-ignore-line
$this->layout = $this->html->add($layout);

$this->initIncludes();

Expand Down
1 change: 1 addition & 0 deletions src/CardDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public function setModel(Model $model, array $fields = null, array $extra = null
$count = $this->initPaginator();
if ($count) {
foreach ($this->model as $m) {
/** @var Card */
$c = $this->cardHolder->add(Factory::factory([$this->card], ['useLabel' => $this->useLabel, 'useTable' => $this->useTable]))->addClass('segment');
$c->setModel($m, $fields);
if ($extra) {
Expand Down
2 changes: 1 addition & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected function initLayout(): void
}

if (is_string($this->layout) || is_array($this->layout)) {
$this->layout = $this->add(Factory::factory($this->layout, ['form' => $this])); // @phpstan-ignore-line
$this->layout = $this->add(Factory::factory($this->layout, ['form' => $this]));
} elseif (is_object($this->layout)) {
$this->layout->form = $this;
$this->add($this->layout);
Expand Down
2 changes: 1 addition & 1 deletion src/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function init(): void
$appUniqueHashesBackup = $this->getApp()->uniqueNameHashes;
$menuElementNameCountsBackup = \Closure::bind(fn () => $this->_elementNameCounts, $this->menu, AbstractView::class)();
try {
$menuRight = $this->menu->addMenuRight(); // @phpstan-ignore-line
$menuRight = $this->menu->addMenuRight();
$menuItemView = View::addTo($menuRight->addItem()->setElement('div'));
$quickSearch = JsSearch::addTo($menuItemView);
$this->stickyGet($quickSearch->name . '_q');
Expand Down
2 changes: 1 addition & 1 deletion src/Panel/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getCallbackUrl(): string
*/
public function setCb(Callback $cb): void
{
$this->cb = $this->add($cb); // @phpstan-ignore-line
$this->cb = $this->add($cb);
}

/**
Expand Down

0 comments on commit d7ed918

Please sign in to comment.