Skip to content

Commit

Permalink
fix SameLevelModuleComparator
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Aug 11, 2024
1 parent 04860e6 commit 7757e84
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
'function_declaration' => true,
'function_to_constant' => true,
'get_class_to_class_keyword' => true,
'get_class_to_class_keyword' => false,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
Expand Down
38 changes: 22 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@
"description": "PHPStan rule for projects using Gacela",
"type": "phpstan-extension",
"license": "MIT",
"authors": [
{
"name": "Jose M. Valera Reales",
"email": "[email protected]"
},
{
"name": "Dave Liddament",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.4",
"gacela-project/gacela": ">=0.1"
},
"require-dev": {
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9.5",
"friendsofphp/php-cs-fixer": "^3.56",
"vimeo/psalm": "^5.1",
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "^9.6",
"friendsofphp/php-cs-fixer": "^3.62",
"vimeo/psalm": "^5.25",
"symfony/var-dumper": "^5.4",
"psalm/plugin-phpunit": "^0.18.4"
"psalm/plugin-phpunit": "^0.18"
},
"suggest": {
"gacela-project/gacela": "Gacela helps you separate your project into modules, focusing on the application/infrastructure layer, decoupled from your domain."
"gacela-project/gacela": "Gacela helps you build modular PHP applications. It helps normalizing the entry point of a module, without interfering with your domain-business logic."
},
"autoload": {
"psr-4": {
Expand All @@ -28,16 +38,6 @@
"GacelaProject\\PhpstanExtension\\Tests\\": "tests/"
}
},
"authors": [
{
"name": "Jose M. Valera Reales",
"email": "[email protected]"
},
{
"name": "Dave Liddament",
"email": "[email protected]"
}
],
"scripts": {
"ctal": [
"@static-clear-cache",
Expand All @@ -64,5 +64,11 @@
"phpstan": "./vendor/bin/phpstan analyze",
"csfix": "./vendor/bin/php-cs-fixer fix",
"csrun": "./vendor/bin/php-cs-fixer fix --dry-run"
},
"config": {
"platform": {
"php": "7.4"
},
"sort-packages": true
}
}
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<psalm
errorLevel="1"
phpVersion="7.4"
findUnusedBaselineEntry="true"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down
6 changes: 5 additions & 1 deletion src/SameLevelModuleComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ private function getModule(string $namespace): string
{
$module = substr($namespace, strlen($this->modulesNamespace));

return substr($module, 0, strpos($module, '\\') ?: strlen($module));
if (false === ($pos = strpos($module, '\\'))) {
$pos = strlen($module);
}

return substr($module, 0, $pos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use GacelaProject\PhpstanExtension\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleB\ModuleBFacadeInterface;
use PHPUnit\Framework\TestCase;

use function get_class;

final class PersonTest extends TestCase
{
public function test_something(): void
Expand All @@ -16,6 +18,6 @@ public function test_something(): void
$this->createStub(ModuleBFacadeInterface::class),
);

self::assertEquals($p::class, $p->asString());
self::assertEquals(get_class($p), $p->asString());
}
}

0 comments on commit 7757e84

Please sign in to comment.