Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHenryIE authored Apr 25, 2024
2 parents 00d0c9b + cedf733 commit e892e9a
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 125 deletions.
6 changes: 3 additions & 3 deletions .github/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.18.1 April 2024

* Fix: check for array before loop

## 0.18.0 April 2024


Expand Down
2 changes: 1 addition & 1 deletion bin/strauss
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ call_user_func(function ($version) {

$app = new BrianHenryIE\Strauss\Console\Application($version);
$app->run();
}, '0.18.0');
}, '0.18.1');
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"require": {
"composer/composer": "*",
"json-mapper/json-mapper": "^2.2",
"symfony/console": "^4|^5|^6",
"symfony/finder": "^4|^5|^6",
"symfony/console": "^4|^5|^6|^7",
"symfony/finder": "^4|^5|^6|^7",
"league/flysystem": "^2.1|^3.0"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion src/ChangeEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(StraussConfig $config, string $workingDir)
$absoluteTargetDir = $workingDir . $config->getTargetDirectory();
}

public function determineReplacements(DiscoveredSymbols $discoveredSymbols)
public function determineReplacements(DiscoveredSymbols $discoveredSymbols): void
{
foreach ($discoveredSymbols->getSymbols() as $symbol) {
if (in_array(
Expand Down
3 changes: 3 additions & 0 deletions src/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ public function cleanupInstalledJson(): void
$installedJsonArray = $installedJsonFile->read();

foreach ($installedJsonArray['packages'] as $key => $package) {
if (!isset($package['autoload'])) {
continue;
}
$packageDir = $this->workingDir . $this->vendorDirectory . ltrim($package['install-path'], '.');
$autoload_key = $package['autoload'];
foreach ($autoload_key as $type => $autoload) {
Expand Down
6 changes: 0 additions & 6 deletions src/Copier.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,9 @@ public function prepareTarget(): void
}
}


/**
*
*/
public function copy(): void
{

/**
* @var string $targetRelativeFilepath
* @var File $file
*/
foreach ($this->files->getFiles() as $file) {
Expand Down
9 changes: 9 additions & 0 deletions src/DependenciesEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class DependenciesEnumerator
*/
protected array $filesAutoloaders = [];

/**
* @var array{}|array<string, array{files?:array<string>,classmap?:array<string>,"psr-4":array<string|array<string>>}> $overrideAutoload
*/
protected array $overrideAutoload = array();

/**
* Constructor.
*
Expand All @@ -67,6 +72,10 @@ public function __construct(
$this->filesystem = new Filesystem(new LocalFilesystemAdapter($this->workingDir));
}

/**
* @return array<string, ComposerPackage> Packages indexed by package name.
* @throws Exception
*/
public function getAllDependencies(): array
{
$this->recursiveGetAllDependencies($this->requiredPackageNames);
Expand Down
46 changes: 2 additions & 44 deletions src/DiscoveredFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
use ArrayAccess;
use BrianHenryIE\Strauss\Composer\ComposerPackage;

class DiscoveredFiles implements ArrayAccess
class DiscoveredFiles
{

/** @var array<string,File> */
protected array $files = [];

/**
* @param File $file
*/
public function add(File $file)
public function add(File $file): void
{
$this->files[$file->getTargetRelativePath()] = $file;
}
Expand All @@ -27,47 +26,6 @@ public function getFiles(): array
return $this->files;
}

/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->files[$offset]);
}

/**
* @return File
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->files[$offset];
}

/**
* @inheritDoc
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->files[] = $value;
} else {
$this->files[$offset] = $value;
}
}

/**
* @inheritDoc
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->files[$offset]);
}


/**
* Returns all found files.
*
Expand Down
4 changes: 4 additions & 0 deletions src/DiscoveredSymbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ abstract class DiscoveredSymbol

protected string $replacement;

/**
* @param string $symbol The classname / namespace etc.
* @param File $file The file it was discovered in.
*/
public function __construct(string $symbol, File $file)
{
$this->symbol = $symbol;
Expand Down
59 changes: 12 additions & 47 deletions src/DiscoveredSymbols.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

namespace BrianHenryIE\Strauss;

use ArrayAccess;
use BrianHenryIE\Strauss\Types\ClassSymbol;
use BrianHenryIE\Strauss\Types\ConstantSymbol;
use BrianHenryIE\Strauss\Types\NamespaceSymbol;

class DiscoveredSymbols implements ArrayAccess
class DiscoveredSymbols
{

/** @var array<string,DiscoveredSymbol> */
/**
* All discovered symbols, grouped by type, indexed by original name.
*
* @var array<string,array<string,DiscoveredSymbol>>
*/
protected array $types = [];

public function __construct()
Expand All @@ -25,9 +27,9 @@ public function __construct()
/**
* @param DiscoveredSymbol $symbol
*/
public function add(DiscoveredSymbol $symbol)
public function add(DiscoveredSymbol $symbol): void
{
$this->types[ get_class($symbol)][$symbol->getOriginalSymbol() ] = $symbol;
$this->types[get_class($symbol)][$symbol->getOriginalSymbol()] = $symbol;
}

/**
Expand All @@ -42,46 +44,6 @@ public function getSymbols(): array
);
}

/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->types[ $offset ]);
}

/**
* @return DiscoveredSymbol
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->types[ $offset ];
}

/**
* @inheritDoc
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->types[] = $value;
} else {
$this->types[ $offset ] = $value;
}
}

/**
* @inheritDoc
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->types[ $offset ]);
}

/**
* @return array<string, ConstantSymbol>
*/
Expand All @@ -98,7 +60,10 @@ public function getNamespaces(): array
return $this->types[NamespaceSymbol::class];
}

public function getClasses()
/**
* @return array<string, ClassSymbol>
*/
public function getClasses(): array
{
return $this->types[ClassSymbol::class];
}
Expand Down
8 changes: 4 additions & 4 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public function __construct(ComposerPackage $dependency, string $packageRelative
$this->sourceAbsolutePath = $sourceAbsolutePath;
}

public function getDependency()
public function getDependency(): ComposerPackage
{
return $this->dependency;
}

public function getSourcePath(string $relativeTo = '')
public function getSourcePath(string $relativeTo = ''): string
{
return str_replace($relativeTo, '', $this->sourceAbsolutePath);
}
Expand Down Expand Up @@ -137,12 +137,12 @@ public function isFilesAutoloaderFile(): bool
return in_array('files', $this->autoloaderTypes, true);
}

public function addDiscoveredSymbol(DiscoveredSymbol $symbol)
public function addDiscoveredSymbol(DiscoveredSymbol $symbol): void
{
$this->discoveredSymbols[$symbol->getOriginalSymbol()] = $symbol;
}

public function getContents()
public function getContents(): string
{

// TODO: use flysystem
Expand Down
11 changes: 9 additions & 2 deletions src/FileEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,16 @@ public function compileFileList(): DiscoveredFiles
return $this->discoveredFiles;
}

protected function addFile(ComposerPackage $dependency, string $packageRelativePath, string $autoloaderType)
/**
* @uses \BrianHenryIE\Strauss\DiscoveredFiles::add()
*
* @param ComposerPackage $dependency
* @param string $packageRelativePath
* @param string $autoloaderType
* @throws \League\Flysystem\FilesystemException
*/
protected function addFile(ComposerPackage $dependency, string $packageRelativePath, string $autoloaderType): void
{

$sourceAbsoluteFilepath = $dependency->getPackageAbsolutePath() . $packageRelativePath;
$outputRelativeFilepath = $dependency->getRelativePath() . $packageRelativePath;
$projectRelativePath = $this->vendorDir . $outputRelativeFilepath;
Expand Down
13 changes: 10 additions & 3 deletions src/FileScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class FileScanner

protected DiscoveredSymbols $discoveredSymbols;

/**
* @var string[]
*/
protected array $excludePackagesFromPrefixing;

/**
* FileScanner constructor.
* @param \BrianHenryIE\Strauss\Composer\Extra\StraussConfig $config
Expand Down Expand Up @@ -63,11 +68,13 @@ public function findInFiles(DiscoveredFiles $files): DiscoveredSymbols
/**
* TODO: Don't use preg_replace_callback!
*
* @uses self::addDiscoveredNamespaceChange()
* @uses self::addDiscoveredClassChange()
*
* @param string $contents
*/
protected function find(string $contents, File $file)
protected function find(string $contents, File $file): void
{

// If the entire file is under one namespace, all we want is the namespace.
// If there were more than one namespace, it would appear as `namespace MyNamespace { ...`,
// a file with only a single namespace will appear as `namespace MyNamespace;`.
Expand All @@ -78,7 +85,7 @@ protected function find(string $contents, File $file)
/x'; // # x: ignore whitespace in regex.
if (1 === preg_match($singleNamespacePattern, $contents, $matches)) {
$this->addDiscoveredNamespaceChange($matches['namespace'], $file);
return $contents;
return;
}

if (0 < preg_match_all('/\s*define\s*\(\s*["\']([^"\']*)["\']\s*,\s*["\'][^"\']*["\']\s*\)\s*;/', $contents, $constants)) {
Expand Down
3 changes: 1 addition & 2 deletions src/Licenser.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ public function addChangeDeclarationToPhpString(

$replaceInMultilineCommentFunction = function ($matches) use (
$licenseDeclaration,
$modifiedDeclaration,
$straussLink
$modifiedDeclaration
) {
// Find the line prefix and use it, i.e. could be none, asterisk or space-asterisk.
$commentLines = explode("\n", $matches[2]);
Expand Down
Loading

0 comments on commit e892e9a

Please sign in to comment.