-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Composer autoloader to locate symbols
Use Composer autoloader to check if the interface definition for the extension attributes does in fact exist.
- Loading branch information
1 parent
56b471b
commit d159afe
Showing
9 changed files
with
230 additions
and
15 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
src/bitExpert/PHPStan/Magento/Autoload/DataProvider/ClassLoaderProvider.php
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,66 @@ | ||
<?php | ||
/* | ||
* This file is part of the phpstan-magento package. | ||
* | ||
* (c) bitExpert AG | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace bitExpert\PHPStan\Magento\Autoload\DataProvider; | ||
|
||
use Composer\Autoload\ClassLoader; | ||
|
||
class ClassLoaderProvider | ||
{ | ||
/** | ||
* @var ClassLoader | ||
*/ | ||
private $composer; | ||
|
||
/** | ||
* ClassLoaderProvider constructor. | ||
* | ||
* @param string $magentoRoot | ||
*/ | ||
public function __construct(string $magentoRoot) | ||
{ | ||
$this->composer = new ClassLoader($magentoRoot.'/vendor'); | ||
$autoloadFile = $magentoRoot.'/vendor/composer/autoload_namespaces.php'; | ||
if (is_file($autoloadFile)) { | ||
$map = require $autoloadFile; | ||
foreach ($map as $namespace => $path) { | ||
$this->composer->set($namespace, $path); | ||
} | ||
} | ||
|
||
$autoloadFile = $magentoRoot.'/vendor/composer/autoload_psr4.php'; | ||
if (is_file($autoloadFile)) { | ||
$map = require $autoloadFile; | ||
foreach ($map as $namespace => $path) { | ||
$this->composer->setPsr4($namespace, $path); | ||
} | ||
} | ||
|
||
$autoloadFile = $magentoRoot.'/vendor/composer/autoload_classmap.php'; | ||
if (is_file($autoloadFile)) { | ||
$classMap = require $autoloadFile; | ||
if (is_array($classMap)) { | ||
$this->composer->addClassMap($classMap); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Check if the given class/interface/tait exists in the defined scope. | ||
* | ||
* @param string $classyConstructName | ||
* @return bool | ||
*/ | ||
public function exists(string $classyConstructName): bool | ||
{ | ||
return $this->composer->findFile($classyConstructName) !== false; | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
tests/bitExpert/PHPStan/Magento/Autoload/DataProvider/ClassLoaderProviderUnitTest.php
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,43 @@ | ||
<?php | ||
/* | ||
* This file is part of the phpstan-magento package. | ||
* | ||
* (c) bitExpert AG | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace bitExpert\PHPStan\Magento\Autoload\DataProvider; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class ClassLoaderProviderUnitTest extends TestCase | ||
{ | ||
/** | ||
* @var ClassLoaderProvider | ||
*/ | ||
private $dataprovider; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->dataprovider = new ClassLoaderProvider(__DIR__ . '/../../../../../../'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function returnsTrueForClassesFound(): void | ||
{ | ||
static::assertTrue($this->dataprovider->exists(ClassLoaderProviderUnitTest::class)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function returnsFalseWhenClassNotFound(): void | ||
{ | ||
static::assertFalse($this->dataprovider->exists('SomeOtherClass')); | ||
} | ||
} |
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