Skip to content

Commit

Permalink
PsrAutoloadingFixer - Fix PSR autoloading outside configured directory
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik authored and keradus committed Mar 19, 2021
1 parent d3aaf70 commit 55a9991
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Fixer/Basic/PsrAutoloadingFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ protected function createConfigurationDefinition()
*/
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
{
if (null !== $this->configuration['dir'] && 0 !== strpos($file->getRealPath(), realpath($this->configuration['dir']))) {
return;
}

$namespace = null;
$namespaceStartIndex = null;
$namespaceEndIndex = null;
Expand Down
6 changes: 6 additions & 0 deletions tests/Fixer/Basic/PsrAutoloadingFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public static function provideFixNewCases()
__DIR__.'/../..',
];

yield 'configured directory (other directory)' => [
'<?php namespace Basic; class Foobar {}',
null,
__DIR__.'/../../Test',
];

yield 'multiple classy elements in file' => [
'<?php interface Foo {} class Bar {}',
];
Expand Down

0 comments on commit 55a9991

Please sign in to comment.