daveliddament / php-language-extensions Goto Github PK
View Code? Open in Web Editor NEWAttributes to define PHP language extensions (to be enforced by static analysis)
License: MIT License
Attributes to define PHP language extensions (to be enforced by static analysis)
License: MIT License
I would like to put the TestTag attribute on a class-level. Marking the entire class as intended for use in tests only.
I sometimes write extremely simple implementations of interfaces that only exist for making writing tests that interact with the interface simpler.
Instead of configuring a mock, you can just create an instance of this class with a couple of constructor arguments.
It is sometimes useful that these classes are available in the library for other code that depends on this library. So writing tests there becomes easier.
What do you think of this change?
Would you accept a pull-request to adjust the attribute for this? And an additional pull-request in DaveLiddament/phpstan-php-language-extensions for the implementation?
Currently #[Package]
is modelled on Java's package
visibility modifier. This does not allow access to sub namespaces. E.g. in Java a call from namespace Foo\Bar
would not be allowed to call a method with package
visibility in Foo\Bar\Baz
.
Options:
#[Package]
to allow calls to sub namespaces.#[Package]
attribute to allow/disallow sub namespaces (possibly allowing as default).See this twitter comment.
Like Java's override: a method with #[Override]
must override a method in the parent class, or implements a method of an interface.
PHP version constraints are, I think, incorrect:
From composer.json
Constraints are:
"php": "^8.0 || ^8.1 || ^8.2"
I think this will allow 8.3, which is wrong as we don't know 8.3 will introduce a break to attributes. (Admittedly it is very unlikely that it will).
Version should either be:
"php": "8.0.* || 8.1.* || 8.2.*"
or
"php": ">=8.0 <8.3"
by @DaveLiddament
from #12
I am using the #[Friend]
attribute to limit access to methods, but it's also complaining about access from test code.
One could argue that test code should be testing the public API of a unit, but it's not that straightforward.
For example, I have a value object inside an aggregate root that should only be managed inside the aggregate. However, I still want my unit tests to test the value object in isolation, which the #[Friend]
complains about.
Is there a more elegant way to deal with this other than suppressing the PHPStan errors?
Thank you.
The #[Friend]
attribute was named after the C++ feature. However this is not likely to be well known in the PHP community.
Update #[Friend]
to a more meaningful name. e.g. #[CallableFrom]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.