Skip to content

Commit

Permalink
Merge pull request #45 from coenjacobs/code-standards
Browse files Browse the repository at this point in the history
Code standards fixed following PSR-2
  • Loading branch information
coenjacobs authored May 23, 2020
2 parents 951287a + b96abc7 commit 6e0d765
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 33 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test

on: [push]

jobs:
php:
name: PHP test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install PHP
uses: shivammathur/[email protected]
with:
php-version: 7.4
- name: Debugging
run: |
php --version
php -m
composer --version
- name: Install dependencies
run: |
composer install --prefer-dist --no-suggest
- name: Run tests
run: |
composer run test
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
}
},
"require-dev": {
"phpunit/phpunit": "^8.5"
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.5"
},
"scripts": {
"test": [
"composer validate",
"phpcs",
"phpunit"
]
}
}
3 changes: 1 addition & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
<ruleset name="mozart">
<description>Coding standard ruleset based on the PSR-2 coding standard.</description>
<rule ref="PSR2"/>
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
<file>./src</file>
</ruleset>
16 changes: 8 additions & 8 deletions src/Composer/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class Package
/** @var array */
public $dependencies = [];

public function __construct($path, $overrideAutoload = null)
{
$this->path = $path;
$this->config = json_decode(file_get_contents($this->path . '/composer.json'));

if (isset($overrideAutoload)) {
$this->config->autoload = $overrideAutoload;
}
public function __construct($path, $overrideAutoload = null)
{
$this->path = $path;
$this->config = json_decode(file_get_contents($this->path . '/composer.json'));

if (isset($overrideAutoload)) {
$this->config->autoload = $overrideAutoload;
}
}

public function findAutoloaders()
Expand Down
10 changes: 5 additions & 5 deletions src/Console/Commands/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ private function findPackages($slugs)
continue;
}

$autoloaders = null;
if (isset($this->config->override_autoload) && isset($this->config->override_autoload->$package_slug) ){
$autoloaders = $this->config->override_autoload->$package_slug;
}
$autoloaders = null;
if (isset($this->config->override_autoload) && isset($this->config->override_autoload->$package_slug)) {
$autoloaders = $this->config->override_autoload->$package_slug;
}

$package = new Package($packageDir, $autoloaders);
$package = new Package($packageDir, $autoloaders);
$package->findAutoloaders();

$config = json_decode(file_get_contents($packageDir . 'composer.json'));
Expand Down
4 changes: 2 additions & 2 deletions src/Mover.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function movePackage(Package $package)
}

if (!isset($this->config->delete_vendor_directories) || $this->config->delete_vendor_directories === true) {
$this->deletePackageVendorDirectories();
$this->deletePackageVendorDirectories();
}
}

Expand Down Expand Up @@ -142,7 +142,7 @@ protected function deletePackageVendorDirectories()
foreach ($this->movedPackages as $movedPackage) {
$packageDir = '/vendor/' . $movedPackage;
if (is_link($packageDir)) {
continue;
continue;
}
$this->filesystem->deleteDir($packageDir);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Replace/NamespaceReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ class NamespaceReplacer extends BaseReplacer

public function replace($contents)
{
$searchNamespace = $this->autoloader->getSearchNamespace();
$searchNamespace = addslashes($this->autoloader->getSearchNamespace());
$dependencyNamespace = addslashes($this->dep_namespace);

return preg_replace_callback(
'/([^a-zA-Z0-9_\x7f-\xff])((?<!' . addslashes( $this->dep_namespace ) . ')' . addslashes($searchNamespace) . '[\\\|;])/U',
'/([^a-zA-Z0-9_\x7f-\xff])((?<!' . $dependencyNamespace . ')' . $searchNamespace . '[\\\|;])/U',
function ($matches) {
return $matches[1] . $this->dep_namespace . $matches[2];
},
Expand Down
25 changes: 12 additions & 13 deletions src/Replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public function replacePackageByAutoloader(Package $package, $autoloader)
$this->replaceInFile($targetFile, $autoloader);
}
}

}
}

Expand All @@ -114,18 +113,18 @@ public function replaceParentClassesInDirectory($directory)
if ('.php' == substr($targetFile, '-4', 4)) {
$contents = $this->filesystem->read($targetFile);

foreach ($replacedClasses as $original => $replacement) {
$contents = preg_replace_callback(
'/(.*)([^a-zA-Z0-9_\x7f-\xff])'. $original . '([^a-zA-Z0-9_\x7f-\xff])/U',
function ($matches) use ($replacement) {
if(preg_match('/(include|require)/', $matches[0], $output_array)) {
return $matches[0];
}
return $matches[1] . $matches[2] . $replacement . $matches[3];
},
$contents
);
}
foreach ($replacedClasses as $original => $replacement) {
$contents = preg_replace_callback(
'/(.*)([^a-zA-Z0-9_\x7f-\xff])'. $original . '([^a-zA-Z0-9_\x7f-\xff])/U',
function ($matches) use ($replacement) {
if (preg_match('/(include|require)/', $matches[0], $output_array)) {
return $matches[0];
}
return $matches[1] . $matches[2] . $replacement . $matches[3];
},
$contents
);
}

$this->filesystem->put($targetFile, $contents);
}
Expand Down

0 comments on commit 6e0d765

Please sign in to comment.