Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Rules/Functions/NoClassConstFetchOnFactoriesFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$fileNamespace = $scope->getNamespace();

if (
$fileNamespace !== null
&& ((defined('APP_NAMESPACE') && str_starts_with($fileNamespace, APP_NAMESPACE))
|| str_starts_with($fileNamespace, 'App\\'))
) {
return [];
}

return [
RuleErrorBuilder::message(sprintf(
'Call to function %s with %s::class is discouraged.',
Expand Down
26 changes: 26 additions & 0 deletions tests/Fixtures/Rules/Functions/bug-9.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) 2023 CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace App\Controllers;

use CodeIgniter\Shield\Models\RememberModel;

class HelloWorld
{
public function touch(): void
{
model(RememberModel::class)
->allowCallbacks(false)
->update();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ public function testRule(): void
],
]);
}

public function testOnAppNamespaceWithNonAppCall(): void
{
$this->analyse([__DIR__ . '/../../Fixtures/Rules/Functions/bug-9.php'], []);
}
}