Giter Site home page Giter Site logo

Comments (11)

ondrejmirtes avatar ondrejmirtes commented on May 9, 2024 2

I just had an idea how to implement this in an elegant way:

Feel free to test it now, it will be released along with PHPStan 0.10.2 in a few days 😊

from phpstan-nette.

adaamz avatar adaamz commented on May 9, 2024

Yes, I already replaced my codebase with ->getComponent() calls.
There is no way (and i think there is no plan for that) how to handle dynamic return type extension for array access/set/unset/...

from phpstan-nette.

novjan avatar novjan commented on May 9, 2024

@CzechBoy Hey, do you have some script or something how to do this change automatically?

from phpstan-nette.

adaamz avatar adaamz commented on May 9, 2024

@novjan I don't remember, but I replaced it with some regex.

from phpstan-nette.

novjan avatar novjan commented on May 9, 2024

Ok, thank you.
Anyway ... do you have some plans about it @ondrejmirtes ?

from phpstan-nette.

novjan avatar novjan commented on May 9, 2024

@ondrejmirtes Hi. It looks that it works only for first offset.

This is ok:

$this['form']->setDefaults([]);

This is ok:

$this['form-checkbox']->setDefaultValue(TRUE)

This is error:

$this['form']['checkbox']->setDefaultValue(TRUE)

from phpstan-nette.

ondrejmirtes avatar ondrejmirtes commented on May 9, 2024

from phpstan-nette.

novjan avatar novjan commented on May 9, 2024

@ondrejmirtes Small example:

protected function createComponentFormData()
{
	$isEdit = TRUE;
	$form = new \Nette\Application\UI\Form;
	$form->addText('text');

	if ($isEdit) {
		$form['form']->addRule($form::FILLED); // Call to an undefined method Nette\ComponentModel\IComponent::addRule().
	}

	$data = $form->addContainer('data');
	$data->addText('text2');

	$form['data']['text2']->setDefaultValue('text'); // Cannot access offset 'text2' on Nette\ComponentModel\IComponent.
}

from phpstan-nette.

ondrejmirtes avatar ondrejmirtes commented on May 9, 2024

PHPStan has no way of knowing the type of $form['data']['text2']. It only works with createComponentFoo style factories.

from phpstan-nette.

ondrejmirtes avatar ondrejmirtes commented on May 9, 2024

Use this pattern:

	$data = $form->addContainer('data');
	$text2 = $data->addText('text2');
	$text2->setDefaultValue('text');

from phpstan-nette.

github-actions avatar github-actions commented on May 9, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from phpstan-nette.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.