Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Aug 31, 2023
1 parent fd200f2 commit 63a9c53
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 265 deletions.
37 changes: 0 additions & 37 deletions src/AutoloadsBuilder.php

This file was deleted.

130 changes: 0 additions & 130 deletions src/ClassMapBuilder.php

This file was deleted.

11 changes: 8 additions & 3 deletions src/MemoizeAttributeCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function __construct(
*
* @throws ReflectionException
*/
public function collectAttributes(array $classMap): Collector
public function collectAttributes(array $classMap): TransientCollection
{
$filterClasses = [];
$classAttributeCollector = $this->classAttributeCollector;
$collector = new Collector();
$collector = new TransientCollection();

foreach ($classMap as $class => $filepath) {
$filterClasses[$class] = true;
Expand All @@ -66,7 +66,12 @@ public function collectAttributes(array $classMap): Collector
$mtime = filemtime($filepath);

if ($timestamp < $mtime) {
$this->io->debug("Refresh attributes of class '$class' in '$filepath' ($timestamp < $mtime)");
if ($timestamp) {
$diff = $mtime - $timestamp;
$this->io->debug("Refresh attributes of class '$class' in '$filepath' ($diff sec ago)");
} else {
$this->io->debug("Collect attributes of class '$class' in '$filepath'");
}

[
$classAttributes,
Expand Down
8 changes: 7 additions & 1 deletion src/MemoizeClassMapFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ public function filter(array $classMap, Closure $filter): array
assert(is_int($mtime));

if ($timestamp < $mtime) {
$this->io->debug("Refresh filtered for '$pathname' ($timestamp < $mtime)");
if ($timestamp) {
$diff = $mtime - $timestamp;
$this->io->debug("Refresh filtered files in '$pathname' ($diff sec ago)");
} else {
$this->io->debug("Filter files in '$pathname'");
}

$keep = $filter($class, $pathname);
$this->state[$pathname] = [ time(), $keep ];
}
Expand Down
22 changes: 7 additions & 15 deletions src/MemoizeClassMapGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getMap(): array

$maps = [];

foreach ($this->state as [ , $map ]) {
foreach ($this->state as [, $map]) {
$maps[] = $map;
}

Expand All @@ -77,33 +77,25 @@ public function getMap(): array
* The path to search in.
* @param non-empty-string|null $excluded
* Regex that matches file paths to be excluded from the classmap
* @param 'classmap'|'psr-0'|'psr-4' $autoloadType
* Optional autoload standard to use mapping rules with the namespace instead of purely doing a classmap
* @param string|null $namespace
* Optional namespace prefix to filter by, only for psr-0/psr-4 autoloading
*
* @throws RuntimeException When the path is neither an existing file nor directory
*/
public function scanPaths(
string $path,
string $excluded = null,
string $autoloadType = 'classmap',
?string $namespace = null
): void {
public function scanPaths(string $path, string $excluded = null): void
{
$this->paths[$path] = true;
[ $timestamp ] = $this->state[$path] ?? [ 0 ];

if ($this->should_update($timestamp, $path)) {
if ($this->shouldUpdate($timestamp, $path)) {
$inner = new ClassMapGenerator();
$inner->avoidDuplicateScans();
$inner->scanPaths($path, $excluded, $autoloadType, $namespace);
$inner->scanPaths($path, $excluded);
$map = $inner->getClassMap()->getMap();

$this->state[$path] = [ time(), $map ];
}
}

private function should_update(int $timestamp, string $path): bool
private function shouldUpdate(int $timestamp, string $path): bool
{
if (!$timestamp) {
return true;
Expand All @@ -127,7 +119,7 @@ private function should_update(int $timestamp, string $path): bool

foreach (new DirectoryIterator($path) as $di) {
if ($di->isDir() && !$di->isDot()) {
if ($this->should_update($timestamp, $di->getPathname())) {
if ($this->shouldUpdate($timestamp, $di->getPathname())) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ private static function buildFileFilter(): Filter
]);
}

private static function render(Collector $collector): string
private static function render(TransientCollection $collector): string
{
return CollectionRenderer::render($collector);
return TransientCollectionRenderer::render($collector);
}
}
4 changes: 2 additions & 2 deletions src/Collector.php → src/TransientCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
namespace olvlvl\ComposerAttributeCollector;

/**
* Collects classes and methods with attributes.
* A collection of attributes used during the collection process.
*
* @internal
*/
final class Collector
final class TransientCollection
{
/**
* @var array<class-string, iterable<TransientTargetClass>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
*
* @internal
*/
final class CollectionRenderer
final class TransientCollectionRenderer
{
public static function render(Collector $collector): string
public static function render(TransientCollection $collector): string
{
$targetClassesCode = self::targetsToCode($collector->classes);
$targetMethodsCode = self::targetsToCode($collector->methods);
Expand Down
68 changes: 0 additions & 68 deletions tests/ClassMapBuilderTest.php

This file was deleted.

Loading

0 comments on commit 63a9c53

Please sign in to comment.