for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace GacelaPhpstan\Rules;
use function strlen;
class SameLevelModuleComparator implements ModuleComparator
{
private string $modulesNamespace;
public function __construct(
string $modulesNamespace
) {
$this->modulesNamespace = rtrim($modulesNamespace, '\\') . '\\';
}
public function isSameModule(?string $namespaceA, ?string $namespaceB): bool
if ($namespaceA === $namespaceB) {
return true;
if ($namespaceA === null || $namespaceB === null) {
return false;
if (!$this->isModulesNamespace($namespaceA)) {
if (!$this->isModulesNamespace($namespaceB)) {
$moduleA = $this->getModule($namespaceA);
$moduleB = $this->getModule($namespaceB);
return ($moduleA === $moduleB);
private function isModulesNamespace(string $namespace): bool
return strpos($namespace, $this->modulesNamespace) === 0;
private function getModule(string $namespace): string
$module = substr($namespace, strlen($this->modulesNamespace));
return substr($module, 0, strpos($module, '\\') ?: strlen($module));