-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
199 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Normalizator\Filter; | ||
|
||
use Normalizator\Attribute\Filter; | ||
use Normalizator\Cache\Cache; | ||
use Normalizator\Finder\File; | ||
|
||
use function in_array; | ||
use function strtolower; | ||
|
||
/** | ||
* Filter which doesn't pass if the file is *.patch. | ||
*/ | ||
#[Filter( | ||
name: 'no_patch_files', | ||
)] | ||
class NoPatchFilesFilter implements NormalizationFilterInterface | ||
{ | ||
public function __construct(private Cache $cache) {} | ||
|
||
public function filter(File $file): bool | ||
{ | ||
$key = static::class . ':' . $file->getPathname(); | ||
|
||
if ($this->cache->has($key)) { | ||
return (bool) $this->cache->get($key); | ||
} | ||
|
||
$filter = $this->check($file); | ||
|
||
$this->cache->set($key, $filter); | ||
|
||
return $filter; | ||
} | ||
|
||
protected function check(File $file): bool | ||
{ | ||
return !in_array(strtolower($file->getExtension()), [ | ||
'patch', | ||
'diff', | ||
], true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
'plain_text', | ||
'no_git', | ||
'no_node_modules', | ||
'no_patch_files', | ||
'no_svn', | ||
'no_vendor', | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
'plain_text', | ||
'no_git', | ||
'no_node_modules', | ||
'no_patch_files', | ||
'no_svn', | ||
'no_vendor', | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
'plain_text', | ||
'no_git', | ||
'no_node_modules', | ||
'no_patch_files', | ||
'no_svn', | ||
'no_vendor', | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
'plain_text', | ||
'no_git', | ||
'no_node_modules', | ||
'no_patch_files', | ||
'no_svn', | ||
'no_vendor', | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Normalizator\Tests\Unit\Filter; | ||
|
||
use Normalizator\Finder\Finder; | ||
use Normalizator\Tests\NormalizatorTestCase; | ||
use org\bovigo\vfs\vfsStream; | ||
use PHPUnit\Framework\Attributes\CoversNothing; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[CoversNothing] | ||
final class NoPatchFilesFilterTest extends NormalizatorTestCase | ||
{ | ||
public function testFilter(): void | ||
{ | ||
$structure = [ | ||
'testing-project' => [ | ||
'patches' => [ | ||
'patch_1.patch' => '', | ||
'patch_2.PATCH' => '', | ||
'patch_3.PaTcH' => '', | ||
'patch_4.diff' => '', | ||
'patch_5.DIFF' => '', | ||
'patch_6.DifF' => '', | ||
], | ||
'src' => [], | ||
'file.php' => '', | ||
], | ||
]; | ||
|
||
vfsStream::create($structure); | ||
|
||
$valid = [ | ||
'vfs://virtual/testing-project' => true, | ||
'vfs://virtual/testing-project/patches' => true, | ||
'vfs://virtual/testing-project/patches/patch_1.patch' => false, | ||
'vfs://virtual/testing-project/patches/patch_2.PATCH' => false, | ||
'vfs://virtual/testing-project/patches/patch_3.PaTcH' => false, | ||
'vfs://virtual/testing-project/patches/patch_4.diff' => false, | ||
'vfs://virtual/testing-project/patches/patch_5.DIFF' => false, | ||
'vfs://virtual/testing-project/patches/patch_6.DifF' => false, | ||
'vfs://virtual/testing-project/src' => true, | ||
'vfs://virtual/testing-project/file.php' => true, | ||
]; | ||
|
||
$filter = $this->createFilter('no_patch_files'); | ||
|
||
$finder = new Finder(); | ||
|
||
foreach ($finder->getTree('vfs://virtual/testing-project') as $key => $file) { | ||
$this->assertSame($valid[$key], $filter->filter($file)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/** | ||
* Miscellaneous fixtures. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
$structure = [ | ||
'initial' => [ | ||
'miscellaneous' => [], | ||
], | ||
'fixed' => [ | ||
'miscellaneous' => [], | ||
], | ||
]; | ||
|
||
$patch_1 = <<<'EOL' | ||
diff --git a/README.md b/README.md | ||
index 802d433..dde8419 100644 | ||
--- a/README.md | ||
+++ b/README.md | ||
@@ -1,7 +1,25 @@ | ||
# Hello, World | ||
-Lorem ipsum dolor sit amet. | ||
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas pharetra dui | ||
+euismod posuere fermentum. Etiam vitae neque ut justo venenatis interdum sit | ||
+amet sed nulla. Etiam a auctor quam. Vivamus cursus augue purus, vitae euismod | ||
+nunc porta nec. Praesent condimentum arcu ac facilisis sodales. In tincidunt | ||
+pretium malesuada. Nunc ut erat quis dolor aliquet tristique in ut nisi. | ||
+ | ||
+ | ||
+Suspendisse a ultrices neque. Pellentesque faucibus, sapien non lobortis | ||
+venenatis, diam turpis eleifend orci, ut congue odio ligula a lectus. In | ||
+finibus, quam non volutpat sagittis, arcu sem sodales ligula, a aliquam turpis | ||
+urna eget sapien. | ||
```sh | ||
echo "Hello, World | ||
``` | ||
+ | ||
+Proin congue, augue auctor maximus facilisis, libero purus bibendum dolor, non | ||
+pulvinar sapien metus condimentum ante. Nulla rhoncus molestie condimentum. | ||
+ | ||
+```Makefile | ||
+build: | ||
+ gcc src.c | ||
+``` | ||
EOL; | ||
|
||
$structure['initial']['miscellaneous']['file_1.patch'] = $patch_1; | ||
$structure['fixed']['miscellaneous']['file_1.patch'] = $patch_1; | ||
|
||
return $structure; |