Skip to content

Added support for readonly properties #112

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

Merged

Conversation

michaelpetri
Copy link

@michaelpetri michaelpetri commented Nov 12, 2021

Q A
Documentation no
Bugfix no
BC Break no
New Feature yes
RFC no
QA no

Description

Requested with #101
Fixes #101

@michaelpetri michaelpetri force-pushed the feature/add-readonly-properties branch from f1adafa to 76ce08f Compare November 12, 2021 18:46
@Ocramius Ocramius added this to the 4.5.0 milestone Nov 12, 2021
@michaelpetri michaelpetri force-pushed the feature/add-readonly-properties branch 2 times, most recently from ef6d5af to e05f300 Compare November 13, 2021 22:05
return $this->removeFlag(self::FLAG_READONLY);
}

public function isReadonly(): bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably get rid of this public API - let's consider #generate() our main API, while reading state is probably not relevant (and not the use-case for this class)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use it in tests, also this version provides such an interface for all other modifiers, imo we should keep it. Also keep in mind this is just a bool, so not much which can be misused?! But your decision!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember that any API we add is API we have to maintain long-term too.

No big issue here though, let's add it 👍

@michaelpetri michaelpetri force-pushed the feature/add-readonly-properties branch 3 times, most recently from bd24fdb to 9fd9b8b Compare November 15, 2021 22:51
@Ocramius
Copy link
Member

Static analysis failing due to parsing: I think I need to set up dependabot here 🤔

@michaelpetri
Copy link
Author

Static analysis failing due to parsing: I think I need to set up dependabot here thinking

I assume the problem here is that psalm runs on php80 and can not parse the test assets which contain php81 syntax?
Maybe the files just need to be excluded. Will check later when we have our half day for research.

@michaelpetri michaelpetri force-pushed the feature/add-readonly-properties branch 2 times, most recently from 3f24eb4 to 264d745 Compare November 17, 2021 17:23
@michaelpetri
Copy link
Author

Static analysis failing due to parsing: I think I need to set up dependabot here thinking

I assume the problem here is that psalm runs on php80 and can not parse the test assets which contain php81 syntax? Maybe the files just need to be excluded. Will check later when we have our half day for research.

The problem is indeed he PHP version <8.1.0, unfortunately excluding the file via psalm.xml is not working. As discussed in slack i dropped the Class from code base and replaced it by an eval() to generate it at runtime.

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢

@Ocramius Ocramius self-assigned this Nov 17, 2021
@Ocramius
Copy link
Member

HMM, static analysis still failed 🤔

Run vendor/bin/psalm  --output-format=github --shepherd --stats
Scanning files...
Analyzing files...

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  60 / 185 (32%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 120 / 185 (64%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 180 / 185 (97%)
░░░░░
Error: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 9 (see https://psalm.dev/173)
🐑 results sent to shepherd.dev 🐑
Error: Process completed with exit code 2.

@michaelpetri
Copy link
Author

HMM, static analysis still failed 🤔

Run vendor/bin/psalm  --output-format=github --shepherd --stats
Scanning files...
Analyzing files...

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░  60 / 185 (32%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 120 / 185 (64%)
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 180 / 185 (97%)
░░░░░
Error: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 9 (see https://psalm.dev/173)
🐑 results sent to shepherd.dev 🐑
Error: Process completed with exit code 2.

Okay that's strange, will try to reproduce local.

Verified

This commit was signed with the committer’s verified signature.
mayeut Matthieu Darbois
Signed-off-by: Michael Petri <mpetri@lyska.io>
@michaelpetri michaelpetri force-pushed the feature/add-readonly-properties branch from 264d745 to e7730fe Compare November 20, 2021 13:50
@michaelpetri
Copy link
Author

Seems like i removed my own commit after the soft reset / rebase issues i faced the last time 🤷‍♂️

Anyway, removed class again, added eval to generate it while runtime. Unfortunately i was not able to solve this issue:

ERROR: MixedAssignment - test/Generator/PropertyGeneratorTest.php:399:9 - Unable to determine the type that $generator is being assigned to (see https://psalm.dev/032)
        $generator = PropertyGenerator::fromReflection($reflectionProperty);

So i decided to add it to baseline, any ideas?

I also realized that psalm is only running on PHP 8.0 in CI, should we extend matrix here as well?

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢

Thanks @michaelpetri!

@Ocramius Ocramius merged commit 4746c4d into laminas:4.5.x Nov 20, 2021
@michaelpetri michaelpetri deleted the feature/add-readonly-properties branch November 20, 2021 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support PHP 8.1 read-only properties
2 participants