Skip to content

Commit

Permalink
Remove src from ComposerDependencySelector
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosas authored Mar 26, 2020
1 parent 150d027 commit a76ff53
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
31 changes: 24 additions & 7 deletions src/Selector/ComposerDependencySelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,51 @@

namespace PhpAT\Selector;

use PhpAT\Parser\AstNode;
use PhpAT\Parser\ClassLike;
use PhpAT\Parser\RegexClassName;

class ComposerDependencySelector extends ComposerSourceSelector implements SelectorInterface
class ComposerDependencySelector implements SelectorInterface
{

/** @var ComposerFileParser */
private $composer;

/**
* @var bool
*/
private $includeDev;

public function __construct(string $composerJson, string $composerLock, bool $includeDev)
{
parent::__construct($composerJson, $includeDev);
$this->composer = new ComposerFileParser($composerJson, $composerLock);
$this->includeDev = $includeDev;
}

public function getDependencies(): array
{
return [];
}

public function injectDependencies(array $dependencies)
{
}

/** @param AstNode[] $astMap */
public function setAstMap(array $astMap)
{
$this->astMap = $astMap;
}

/** @return ClassLike[] */
public function select(): array
{
$namespaces = $this->composer->getDeepRequirementNamespaces($this->includeDev);
$dependencySelectors = array_map(

return array_map(
function (string $namespace) {
return new RegexClassName($namespace . '*');
},
$namespaces
);

return array_merge($dependencySelectors, parent::select());
}

public function getParameter(): string
Expand Down
3 changes: 1 addition & 2 deletions src/Selector/ComposerSourceSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@

class ComposerSourceSelector implements SelectorInterface
{

/** @var string */
private $composerJson;

/** @var AstNode[] */
private $astMap;

protected $includeDev;
private $includeDev;

public function __construct(string $composerJson, bool $includeDev)
{
Expand Down
12 changes: 12 additions & 0 deletions tests/architecture/ComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ public function testOnlyDependsOnComposerDependencies(): Rule
return $this->newRule
->classesThat(Selector::areAutoloadableFromComposer(__DIR__ . '/../../composer.json'))
->canOnlyDependOn()
->classesThat(Selector::areAutoloadableFromComposer(__DIR__ . '/../../composer.json'))
->classesThat(Selector::areDependenciesFromComposer(__DIR__ . '/../../composer.json', __DIR__ . '/../../composer.lock'))
->build();
}

public function testAssertionsDoNotDependOnVendors(): Rule
{
return $this->newRule
->classesThat(Selector::haveClassName('PhpAT\Rule\Assertion\*'))
->mustNotDependOn()
->classesThat(Selector::areDependenciesFromComposer(__DIR__ . '/../../composer.json', __DIR__ . '/../../composer.lock'))
->excludingClassesThat(Selector::haveClassName('PHPAT\*'))
->andExcludingClassesThat(Selector::haveClassName('Psr\*'))
->build();
}
}
4 changes: 2 additions & 2 deletions tests/unit/Selector/ComposerDependencySelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public function testExtractsDependencies(): void
$this->assertTrue($this->oneSelectedMatches($selected, 'Safe\\Foo'));
}

public function testIncludesOwnNamespaces(): void
public function testDoesNotIncludeOwnNamespaces(): void
{
$selected = $this->select(false);
$this->assertTrue($this->oneSelectedMatches($selected, 'Source\\Namespace\\Foo'));
$this->assertFalse($this->oneSelectedMatches($selected, 'Source\\Namespace\\Foo'));
}

/** @param ClassLike[] $selected */
Expand Down

0 comments on commit a76ff53

Please sign in to comment.