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

Form container semi dynamic names #421

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/Compiler/NodeVisitor/AddVarTypesNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use PHPStan\Type\ThisType;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;

final class AddVarTypesNodeVisitor extends NodeVisitorAbstract implements VariablesNodeVisitorInterface
{
Expand Down Expand Up @@ -94,7 +95,6 @@ public function enterNode(Node $node): ?Node
}

$variableType = $variable->getType();

if ($variableType instanceof ThisType) {
// $this(SomeClass) is transformed to $this, but we want to use SomeClass instead
$variableType = $variableType->getStaticObjectType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
namespace Efabrica\PHPStanLatte\Tests\Rule\LatteTemplatesRule\PresenterWithoutModule\Fixtures;

use Efabrica\PHPStanLatte\Tests\Rule\LatteTemplatesRule\PresenterWithoutModule\Source\CustomForm;
use Efabrica\PHPStanLatte\Tests\Rule\LatteTemplatesRule\PresenterWithoutModule\Source\Slide;
use Nette\Application\UI\Form;
use Nette\Forms\Container;
use Nette\Forms\Controls\SubmitButton;
use stdClass;

final class FormsPresenter extends ParentPresenter
{
public Slide $slide;

public function actionDefault(): void
{
parent::actionDefault();
$this->template->dynamicVariable = $this->name;
$this->template->dynamicPropertyFetch = new stdClass();
$this->template->slide = new stdClass();
$this->template->slide = $this->slide;
}

protected function createComponentFirstForm(): Form
Expand Down Expand Up @@ -61,14 +62,18 @@ protected function createComponentSecondForm(): Form
$dynamicVariable = $this->name;
$form->addText($dynamicVariable, 'Dynamic name (variable)');

$dynamicPropertyFetch = new stdClass();
$form->addPassword($dynamicPropertyFetch->name, 'Dynamic name (property fetch)');
$slide = $this->slide;
$form->addPassword($slide->name, 'Dynamic name (property fetch)');

$slide = new stdClass();
$container = $form->addContainer($slide->id);
$container->addText('title', 'Title');
$container->addImageButton('image', 'Image');

$multiContainer = $form->addContainer('multi');
$slideTitleContainer = $multiContainer->addContainer($slide->title);
$slideTitleContainer->addText('en');
$slideTitleContainer->addText('sk');

$defaults = [];
$form->setDefaults($defaults);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,21 @@
{input radio_list:4}{label radio_list:4 /}
{php \PHPStan\dumpType($form[$dynamicVariable])}
{input $dynamicVariable}
{php \PHPStan\dumpType($form[$dynamicPropertyFetch->name])}
{input $dynamicPropertyFetch->name}
{php \PHPStan\dumpType($form[$slide->name])}
{input $slide->name}
{formContainer $slide->id}
{input title}
{input image}
{/formContainer}

{formContainer "multi-$slide->title"}
{input en}
{input sk}
{/formContainer}

{input multi-{$slide->title}-en}
{input multi-{$slide->title}-sk}

{input submit, 'class' => 'btn'}
{/form}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ public function testForms(): void
],
[
'Form control with name "2" probably does not exist.',
164,
173,
'default.latte',
],
[
'Form control with name "10" probably does not exist.',
169,
178,
'default.latte',
],
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Efabrica\PHPStanLatte\Tests\Rule\LatteTemplatesRule\PresenterWithoutModule\Source;

final class Slide
{
public int $id;

public string $name;

public string $title;
}