symplify/skipper

Skip files by rule class, directory, file or fnmatch

Maintainers

Details

github.com/symplify/skipper

Source

Installs: 2 545 059

Dependents: 1

Suggesters: 0

Security: 0

Stars: 18

Watchers: 3

Forks: 1

This package is auto-updated.

Last update: 2022-08-16 12:19:33 UTC


README

Skip files by rule class, fnmatch or regex.

Downloads total

Install

composer require symplify/skipper

Register package in your config:

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\Skipper\ValueObject\SkipperConfig;

return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->import(SkipperConfig::FILE_PATH);
};

Use

1. Configure with Option::SKIP parameter.

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\Skipper\ValueObject\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
    $parameters = $containerConfigurator->parameters();

    $parameters->set(Option::SKIP, [
        // absolute directory
        __DIR__ . '/some-path',

        // absolute file
        __DIR__ . '/some-path/some-file.php',

        // with mask
        '*/Fixture/*',

        // specific class
        SomeClass::class,
    ]);
};

Or for rules and paths specific ignores:

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\Skipper\ValueObject\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
    $parameters = $containerConfigurator->parameters();

    $parameters->set(Option::SKIP, [
        // specific class
        SomeClass::class => [__DIR__ . '/src/OnlyHere'],

        // class code in paths
        SomeSniff::class . '.SomeCode' => ['*Sniff.php', '*YamlFileLoader.php'],
    ]);
};

2. Configure with Option::ONLY parameter.

This is exact invert of SKIP. The SomeFixer will run only if in defined paths:

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\Skipper\ValueObject\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
    $parameters = $containerConfigurator->parameters();
    $parameters->set(Option::ONLY, [
        // this should be removed in the future, with all dead comments
        SomeFixer::class => [__DIR__ . '/src/Controller'],
    ]);
};

3. Use Skipper service in Your Project

You have 3 way to decide, if the something should be skipped:

  • the element
  • the file info
  • the element in the file info
use Symplify\Skipper\Skipper\Skipper;
use Symplify\SmartFileSystem\SmartFileInfo;

final class SomeClass
{
    /**
     * @var Skipper
     */
    private $skipper;

    public function __construct(Skipper $skipper)
    {
        $this->skipper = $skipper;
    }

    public function run(string|object $element, SmartFileInfo $fileInfo): void
    {
        // 1. skip the element?
        $shouldBeSkipped = $this->skipper->shouldSkipElement($element);

        // 2. skip the file path?
        $shouldBeSkipped = $this->skipper->shouldSkipFileInfo($fileInfo);

        // 3. skip the element in the file path?
        $shouldBeSkipped = $this->skipper->shouldSkipElementAndFileInfo($element, $fileInfo);
    }
}

Report Issues

In case you are experiencing a bug or want to request a new feature head over to the Symplify monorepo issue tracker

Contribute

The sources of this package are contained in the Symplify monorepo. We welcome contributions for this package on symplify/symplify.