for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Funivan\Cs\Fs;
/**
* @author Ivan Shcherbak <[email protected]> 2016
*/
class FileFilter {
* @var callable[]
private $callback = [];
* @param string[] $regex
* @return $this
public function mimeType($regex) {
$this->callback[] = function (File $file) use ($regex) {
return $this->processMatch($regex, $file->getMimeType());
};
return $this;
}
public function path(array $regex) {
return $this->processMatch($regex, $file->getPath());
public function name(array $regex) {
return $this->processMatch($regex, $file->getName());
* @param string[] $ext
public function extension(array $ext) {
$this->callback[] = function (File $file) use ($ext) {
return in_array($file->getExtension(), $ext);
* @param int[] $status
public function status(array $status) {
$this->callback[] = function (File $file) use ($status) {
return in_array($file->getStatus(), $status);
public function notDeleted() {
$this->status([
File::STATUS_ADDED,
File::STATUS_COPIED,
File::STATUS_RENAMED,
File::STATUS_MODIFIED,
File::STATUS_UNKNOWN,
]);
* @param File $fileInfo
* @return bool
public function isValid(File $fileInfo) {
foreach ($this->callback as $callback) {
if ($callback($fileInfo) === false) {
return false;
return true;
* @param string $value
private function processMatch(array $regex, $value) {
foreach ($regex as $reg) {
if (preg_match($reg, $value) === 1) {