Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
vendor/*
# IDE Shizzle; it is recommended to use a global .gitignore for this but since this is an OSS project we want to make
# it easy to contribute
.idea
/nbproject/private/
.buildpath
.project
.settings

# Build folder and vendor folder are generated code; no need to version this
build/*
vendor/*
composer.phar

# By default the phpunit.xml.dist is provided; you can override this using a local config file
phpunit.xml
43 changes: 43 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
before_commands:
- "composer install --no-dev --prefer-source"

tools:
external_code_coverage:
enabled: true
timeout: 300
filter:
excluded_paths: ["examples", "tests", "vendor"]
php_code_sniffer:
enabled: true
config:
standard: PSR2
filter:
paths: ["src/*", "tests/*"]
excluded_paths: []
php_cpd:
enabled: true
excluded_dirs: ["examples", "tests", "vendor"]
php_cs_fixer:
enabled: true
config:
level: all
filter:
paths: ["src/*", "tests/*"]
php_loc:
enabled: true
excluded_dirs: ["examples", "tests", "vendor"]
php_mess_detector:
enabled: true
config:
ruleset: phpmd.xml.dist
design_rules: { eval_expression: false }
filter:
paths: ["src/*"]
php_pdepend:
enabled: true
excluded_dirs: ["examples", "tests", "vendor"]
php_analyzer:
enabled: true
filter:
paths: ["src/*", "tests/*"]
sensiolabs_security_checker: true
39 changes: 39 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
language: php
php: [7.0, 7.1, 7.2, nightly ]
sudo: false

env:
global:
- VERSION=$(echo $TRAVIS_TAG | cut -c 2-10)

install:
- composer install --no-interaction --prefer-dist -o

jobs:
include:
- stage: Test
script:
- vendor/bin/phpunit

- stage: Coverage
php: 7.1
script:
- vendor/bin/phpunit
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml

allow_failures:
- php: nightly

cache:
directories:
- $HOME/.composer/cache/files

notifications:
irc: irc.freenode.org#phpdocumentor
slack:
secure: fjumM0h+4w3EYM4dpgqvpiCug7m4sSIC5+HATgwga/Nrc6IjlbWvGOv3JPgD3kQUhi18VmZfUYPmCv916SIbMnv8JWcrSaJXnPCgmxidvYkuzQDIw1HDJbVppGnkmwQA/qjIrM3sIEMfnu/arLRJQLI363aStZzGPxwIa4PDKcg=
email:
- me@mikevanriel.com
- ashnazg@php.net
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
[![Build Status](https://travis-ci.org/phpDocumentor/FlyFinder.svg?branch=master)](https://travis-ci.org/phpDocumentor/FlyFinder)
[![Build status](https://ci.appveyor.com/api/projects/status/2suhb82i8pf3m5xv/branch/master?svg=true)](https://ci.appveyor.com/project/ashnazg/flyfinder/branch/master)
[![Code Coverage](https://scrutinizer-ci.com/g/phpDocumentor/FlyFinder/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/phpDocumentor/FlyFinder/?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/phpDocumentor/FlyFinder/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/phpDocumentor/FlyFinder/?branch=master)


FlyFinder
================================================================================================================

FlyFinder is a plugin for [Flysystem](http://flysystem.thephpleague.com/) that will enable you to find files
based on certain criteria.

FlyFinder can search for files and directories that are hidden, that have a certain extension or that exist in a
certain path.
FlyFinder can search for files that are hidden (either because they are hidden files themselves, or because they are
inside a hidden directory), that have a certain extension, or that exist in a certain path.

Flyfinder does *not* return directories themselves... only files.

## Installation

Expand Down Expand Up @@ -38,6 +46,7 @@ FlyFinder will need specifications to know what to look for. The following speci
- IsHidden (this specification will return `true` when a file or directory is hidden,
- HasExtension (this specification will return `true` when a file or directory has the specified extension),
- InPath (this specification will return `true` when a file is in the given path. Wildcards are allowed.)
- note that this path should be considered relative to the `$filesystem`'s path

Specifications can be instantiated as follows:

Expand Down
56 changes: 56 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
build: false
clone_folder: c:\flyfinder
max_jobs: 3
platform: x86
pull_requests:
do_not_increment_build_number: true
version: '{build}.{branch}'
skip_tags: true
branches:
only:
- master

environment:
matrix:
- PHP_VERSION: '7.0.27'
VC_VERSION: 'VC14'
- PHP_VERSION: '7.1.13'
VC_VERSION: 'VC14'
- PHP_VERSION: '7.2.1'
VC_VERSION: 'VC15'
matrix:
fast_finish: false

cache:
- c:\php -> appveyor.yml
- '%LOCALAPPDATA%\Composer\files'

init:
- SET PATH=c:\php\%PHP_VERSION%;%PATH%

install:
- IF NOT EXIST c:\php mkdir c:\php
- IF NOT EXIST c:\php\%PHP_VERSION% mkdir c:\php\%PHP_VERSION%
- cd c:\php\%PHP_VERSION%
- IF NOT EXIST php-installed.txt appveyor DownloadFile http://windows.php.net/downloads/releases/php-%PHP_VERSION%-Win32-%VC_VERSION%-x86.zip
- IF NOT EXIST php-installed.txt 7z x php-%PHP_VERSION%-Win32-%VC_VERSION%-x86.zip -y >nul
- IF NOT EXIST php-installed.txt del /Q *.zip
- IF NOT EXIST php-installed.txt copy /Y php.ini-development php.ini
- IF NOT EXIST php-installed.txt echo max_execution_time=1200 >> php.ini
- IF NOT EXIST php-installed.txt echo date.timezone="UTC" >> php.ini
- IF NOT EXIST php-installed.txt echo extension_dir=ext >> php.ini
- IF NOT EXIST php-installed.txt echo extension=php_curl.dll >> php.ini
- IF NOT EXIST php-installed.txt echo extension=php_openssl.dll >> php.ini
- IF NOT EXIST php-installed.txt echo extension=php_mbstring.dll >> php.ini
- IF NOT EXIST php-installed.txt echo extension=php_fileinfo.dll >> php.ini
- IF NOT EXIST php-installed.txt echo zend.assertions=1 >> php.ini
- IF NOT EXIST php-installed.txt echo assert.exception=On >> php.ini
- IF NOT EXIST php-installed.txt appveyor DownloadFile https://getcomposer.org/composer.phar
- IF NOT EXIST php-installed.txt echo @php %%~dp0composer.phar %%* > composer.bat
- IF NOT EXIST php-installed.txt type nul >> php-installed.txt
- cd c:\flyfinder
- composer install --no-interaction --prefer-dist --no-progress

test_script:
- cd c:\flyfinder
- vendor/bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// dummy file
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// dummy file
2 changes: 2 additions & 0 deletions examples/03-sample-files/src/phpDocumentor/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// dummy file
2 changes: 2 additions & 0 deletions examples/03-sample-files/src/phpDocumentor/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// dummy file
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// dummy file
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// dummy file
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
// dummy file
34 changes: 34 additions & 0 deletions examples/03-sample-phpdoc-layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
require_once(__DIR__ . '/../vendor/autoload.php');

use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
use Flyfinder\Finder;
use Flyfinder\Path;
use Flyfinder\Specification\IsHidden;
use Flyfinder\Specification\HasExtension;
use Flyfinder\Specification\InPath;
use Flyfinder\Specification\AndSpecification;

// (03-sample-files based on some phpDocumentor2 src files)
$filesystem = new Filesystem(new Local(__DIR__ . '/03-sample-files'));
$filesystem->addPlugin(new Finder());

/*
* "phpdoc -d src -i src/phpDocumentor/DomainModel"
* should result in src/Cilex and src/phpDocumentor/. files being found,
* but src/phpDocumentor/DomainModel files being left out
*/
$dashDirectoryPath = new InPath(new Path('src'));
$dashIgnorePath = new InPath(new Path('src/phpDocumentor/DomainModel'));
$isHidden = new IsHidden();
$isPhpFile = new HasExtension(['php']);
$spec = new AndSpecification($dashDirectoryPath, $dashIgnorePath->notSpecification());
$spec->andSpecification($isHidden->notSpecification());
$spec->andSpecification($isPhpFile);

$generator = $filesystem->find($spec);
$result = [];
foreach($generator as $value) {
$result[] = $value;
}
23 changes: 23 additions & 0 deletions phpmd.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ruleset
name="ProxyManager rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
>
<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/unusedcode.xml"/>
<rule ref="rulesets/design.xml">
<!-- eval is needed to generate runtime classes -->
<exclude name="EvalExpression"/>
</rule>
<rule ref="rulesets/naming.xml">
<exclude name="LongVariable"/>
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="minimum">40</property>
</properties>
</rule>
</ruleset>
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<testsuite name="unit">
<directory>./tests/unit/</directory>
</testsuite>
<testsuite name="unit">
<directory>./tests/integration/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
Expand Down
16 changes: 14 additions & 2 deletions src/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use Flyfinder\Specification\SpecificationInterface;

/**
* Flysystem plugin to add file finding capabilities to the filesystem entity
* Flysystem plugin to add file finding capabilities to the filesystem entity.
*
* Note that found *directories* are **not** returned... only found *files*.
*/
class Finder implements PluginInterface
{
Expand Down Expand Up @@ -49,19 +51,29 @@ public function setFilesystem(FilesystemInterface $filesystem)
/**
* Find the specified files
*
* Note that only found *files* are yielded at this level,
* which go back to the caller.
*
* @param SpecificationInterface $specification
* @return Generator
*/
public function handle(SpecificationInterface $specification)
{
foreach ($this->yieldFilesInPath($specification, '') as $path) {
yield $path;
if (isset($path['type']) && $path['type'] === 'file') {
yield $path;
}
}
}

/**
* Recursively yield files that meet the specification
*
* Note that directories are also yielded at this level,
* since they have to be recursed into. Yielded directories
* will not make their way back to the caller, as they are filtered out
* by {@link handle()}.
*
* @param SpecificationInterface $specification
* @param string $path
* @return Generator
Expand Down
Loading