forked from https://github.com/symfony/symfony
cc170ebc33
This PR was squashed before being merged into the 4.2-dev branch (closes #27891).
Discussion
----------
[Finder] Allow arrays as parameters of some methods for better fluent experience and code readability
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | none
| License | MIT
| Doc PR | symfony/symfony-docs#10038
Makes the Finder library a little more convenient to use by allowing the use of arrays as parameters of methods that can be called multiple times.
This way of doing things was already present for the `Finder::in()` and `Finder::exclude()` methods, it has been extended to other methods that can be called several times to cumulate their effects.
This allows a better use of fluent methods by avoiding breaking the chaining to iterate on array variables (a little more complexity in the Finder library for less complexity in applications that uses it).
```php
// we could use
$finder = Finder::create()->in($fileRepository)->name($fileList);
// instead of
$finder = Finder::create()->in($fileRepository);
foreach ($fileList as $file) {
$finder->name($file);
}
```
In `.php_cs` files, this would make the code more readable by separating the configuration of the execution code:
```php
<?php
const RULES = [
'@Symfony' => true,
'@Symfony:risky' => true,
];
const EXCLUDED_DIRS = [
// directories containing files with content that is autogenerated by `var_export`, which breaks CS in output code
'Symfony/Component/Cache/Tests/Marshaller/Fixtures',
'Symfony/Component/DependencyInjection/Tests/Fixtures',
// ...
];
const EXCLUDED_FILES = [
// file content autogenerated by `var_export`
'Symfony/Component/Translation/Tests/fixtures/resources.php',
// test template
'Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Resources/Custom/_name_entry_label.html.php',
// ...
];
return PhpCsFixer\Config::create()
->setRules(RULES)
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->append(array(__FILE__))
->exclude(EXCLUDED_DIRS)
->notPath(EXCLUDED_FILES)
)
;
```
TODO
- [x] complete the tests to validate the new syntax on all modified methods
- [x] submit changes to the Finder documentation
Commits
-------
|
||
---|---|---|
.composer | ||
.github | ||
src/Symfony | ||
.editorconfig | ||
.gitignore | ||
.php_cs.dist | ||
.travis.yml | ||
appveyor.yml | ||
CHANGELOG-4.0.md | ||
CHANGELOG-4.1.md | ||
composer.json | ||
CONTRIBUTING.md | ||
CONTRIBUTORS.md | ||
LICENSE | ||
link | ||
phpunit | ||
phpunit.xml.dist | ||
README.md | ||
UPGRADE-4.0.md | ||
UPGRADE-4.1.md | ||
UPGRADE-4.2.md | ||
UPGRADE-5.0.md |
Symfony is a PHP framework for web applications and a set of reusable PHP components. Symfony is used by thousands of web applications (including BlaBlaCar.com and Spotify.com) and most of the popular PHP projects (including Drupal and Magento).
Installation
- Install Symfony with Composer (see requirements details).
- Symfony follows the semantic versioning strictly, publishes "Long Term Support" (LTS) versions and has a release process that is predictable and business-friendly.
Documentation
- Read the Getting Started guide if you are new to Symfony.
- Try the Symfony Demo application to learn Symfony in practice.
- Master Symfony with the Guides and Tutorials, the Components docs and the Best Practices reference.
Community
- Join the Symfony Community and meet other members at the Symfony events.
- Get Symfony support on Stack Overflow, Slack, IRC, etc.
- Follow us on GitHub, Twitter and Facebook.
- Read our Code of Conduct and meet the CARE Team
Contributing
Symfony is an Open Source, community-driven project with thousands of contributors. Join them contributing code or contributing documentation.
Security Issues
If you discover a security vulnerability within Symfony, please follow our disclosure procedure.
About Us
Symfony development is sponsored by SensioLabs, led by the Symfony Core Team and supported by Symfony contributors.