This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Fabien Potencier cc170ebc33 feature #27891 [Finder] Allow arrays as parameters of some methods for better fluent experience and code readability (jfredon)
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
-------

ad97cd7121 [Finder] Allow arrays as parameters of some methods for better fluent experience and code readability
2018-07-16 14:56:49 +02:00
.composer Drop hirak/prestissimo 2016-05-12 07:44:15 -05:00
.github Added symfony/contracts: a set of abstractions extracted out of the components 2018-07-11 10:17:42 +02:00
src/Symfony [Finder] Allow arrays as parameters of some methods for better fluent experience and code readability 2018-07-16 14:56:42 +02:00
.editorconfig Add EditorConfig File 2012-06-16 14:08:15 +02:00
.gitignore Add appveyor.yml for C.I. on Windows 2015-08-25 23:41:37 +02:00
.php_cs.dist [ProxyManagerBridge][DI] allow proxifying interfaces with "lazy: Some\ProxifiedInterface" 2018-07-09 16:45:45 +02:00
.travis.yml Added symfony/contracts: a set of abstractions extracted out of the components 2018-07-11 10:17:42 +02:00
appveyor.yml Merge branch '3.4' into 4.0 2018-04-26 18:12:06 +02:00
CHANGELOG-4.0.md updated CHANGELOG for 4.0.12 2018-06-25 15:02:02 +02:00
CHANGELOG-4.1.md updated CHANGELOG for 4.1.1 2018-06-25 15:06:25 +02:00
composer.json renamed Contract to Contracts 2018-07-13 19:06:58 +02:00
CONTRIBUTING.md Mention the community review guide 2016-12-18 22:02:35 +01:00
CONTRIBUTORS.md update CONTRIBUTORS for 2.8.42 2018-06-25 14:01:37 +02:00
LICENSE fixed years in copyright 2018-01-03 08:23:28 +01:00
link [DI] Minor performance tweak in PriorityTaggedServiceTrait 2018-05-03 17:03:52 -07:00
phpunit Default testsuite to latest PHPUnit 6.* 2018-05-25 15:04:04 +02:00
phpunit.xml.dist Added symfony/contracts: a set of abstractions extracted out of the components 2018-07-11 10:17:42 +02:00
README.md Merge branch '2.8' into 3.4 2018-05-25 16:50:57 +02:00
UPGRADE-4.0.md Merge branch '2.8' into 3.4 2018-05-31 12:13:22 +02:00
UPGRADE-4.1.md Merge branch '4.0' into 4.1 2018-05-31 12:17:53 +02:00
UPGRADE-4.2.md feature #27774 [FrameworkBundle] allow turning routes to utf8 mode by default (nicolas-grekas) 2018-07-09 16:14:24 +02:00
UPGRADE-5.0.md [DoctrineBridge] Inject the entity manager instead of the class metadata factory in DoctrineExtractor 2018-07-13 22:22:15 +02:00

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

Documentation

Community

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.