Skip to content

Commit 5b138b0

Browse files
committed
style: satisfy Psalm errorLevel 1 and deprecate ActiveRecord TransactionException
- Make leaf classes final (Facade, ConfigurationException, the Spiral/Laravel bridges) and mark ActiveQuery/ActiveRepository as @api since they are user extension points. - Add the #[\Override] attributes and purity/immutability annotations Psalm requires at errorLevel 1, and type the repository $orderBy argument. - Deprecate Cycle\ActiveRecord\Exception\Transaction\TransactionException, aliasing it to Cycle\Transaction\Exception\TransactionException (mirroring TransactionMode); the @throws now reference the cycle/transaction exception. - Consolidate the IDE/static-analysis stubs into resources/stubs.php.
1 parent b7dd19c commit 5b138b0

16 files changed

Lines changed: 311 additions & 359 deletions

File tree

composer.lock

Lines changed: 233 additions & 321 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
</ignoreFiles>
2323
</projectFiles>
2424
<stubs>
25-
<file name="stubs/TransactionMode.php"/>
25+
<file name="resources/stubs.php"/>
2626
</stubs>
2727
</psalm>

resources/stubs.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ActiveRecord\Exception\Transaction;
6+
7+
/**
8+
* IDE/static-analysis stub. It is never loaded at runtime — the real
9+
* {@see TransactionException} is an alias of
10+
* {@see \Cycle\Transaction\Exception\TransactionException} created in
11+
* src/Exception/Transaction/TransactionException.php.
12+
*
13+
* @deprecated Use {@see \Cycle\Transaction\Exception\TransactionException} instead.
14+
*/
15+
final class TransactionException extends \RuntimeException {}
16+
17+
namespace Cycle\ActiveRecord;
18+
19+
/**
20+
* IDE/static-analysis stub. It is never loaded at runtime — the real
21+
* {@see TransactionMode} is an alias of
22+
* {@see \Cycle\Transaction\TransactionMode} created in src/TransactionMode.php.
23+
*
24+
* @deprecated Use {@see \Cycle\Transaction\TransactionMode} instead.
25+
*/
26+
enum TransactionMode
27+
{
28+
case Ignore;
29+
case Current;
30+
case OpenNew;
31+
}

src/ActiveRecord.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Cycle\ActiveRecord;
66

7-
use Cycle\ActiveRecord\Exception\Transaction\TransactionException;
87
use Cycle\ActiveRecord\Internal\TransactionFacade;
98
use Cycle\ActiveRecord\Query\ActiveQuery;
109
use Cycle\Database\DatabaseInterface;
@@ -13,6 +12,7 @@
1312
use Cycle\ORM\ORMInterface;
1413
use Cycle\ORM\RepositoryInterface;
1514
use Cycle\ORM\SchemaInterface;
15+
use Cycle\Transaction\Exception\TransactionException;
1616
use Cycle\Transaction\TransactionMode;
1717

1818
/**

src/Bridge/Laravel/Providers/ActiveRecordProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
use Cycle\ActiveRecord\Facade;
88
use Illuminate\Support\ServiceProvider;
99

10-
class ActiveRecordProvider extends ServiceProvider
10+
final class ActiveRecordProvider extends ServiceProvider
1111
{
12+
/**
13+
* @psalm-external-mutation-free
14+
*/
15+
#[\Override]
1216
public function register(): void
1317
{
1418
Facade::setContainer($this->app);

src/Bridge/Spiral/Bootloader/ActiveRecordBootloader.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@
99
use Spiral\Boot\Bootloader\Bootloader;
1010
use Spiral\Cycle\Bootloader\CycleOrmBootloader;
1111

12-
class ActiveRecordBootloader extends Bootloader
12+
final class ActiveRecordBootloader extends Bootloader
1313
{
14+
/**
15+
* @psalm-pure
16+
*/
17+
#[\Override]
1418
public function defineDependencies(): array
1519
{
1620
return [
1721
CycleOrmBootloader::class,
1822
];
1923
}
2024

25+
/**
26+
* @psalm-external-mutation-free
27+
*/
2128
public function init(ContainerInterface $container): void
2229
{
2330
Facade::setContainer($container);

src/Exception/ActiveRecordException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44

55
namespace Cycle\ActiveRecord\Exception;
66

7+
/**
8+
* @psalm-mutable
9+
*/
710
interface ActiveRecordException extends \Throwable {}

src/Exception/ConfigurationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
namespace Cycle\ActiveRecord\Exception;
66

7-
class ConfigurationException extends \RuntimeException implements ActiveRecordException {}
7+
final class ConfigurationException extends \RuntimeException implements ActiveRecordException {}

src/Exception/Transaction/TransactionException.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44

55
namespace Cycle\ActiveRecord\Exception\Transaction;
66

7-
use Cycle\ActiveRecord\Exception\ActiveRecordException;
8-
9-
class TransactionException extends \RuntimeException implements ActiveRecordException {}
7+
/** @psalm-suppress DeprecatedClass The alias intentionally targets the deprecated class name. */
8+
\class_alias(\Cycle\Transaction\Exception\TransactionException::class, TransactionException::class);

src/Facade.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
/**
1414
* @internal
1515
*/
16-
class Facade
16+
final class Facade
1717
{
1818
private static ?ORMInterface $orm = null;
1919
private static ?ContainerInterface $container = null;
2020
private static ?DatabaseManager $dbal = null;
2121

22+
/**
23+
* @psalm-external-mutation-free
24+
*/
2225
public static function setContainer(ContainerInterface $container): void
2326
{
2427
self::$container = $container;
@@ -40,6 +43,9 @@ public static function getDatabaseManager(): DatabaseManager
4043
return self::$dbal ??= self::getFromContainer(DatabaseManager::class);
4144
}
4245

46+
/**
47+
* @psalm-external-mutation-free
48+
*/
4349
public static function reset(): void
4450
{
4551
self::$orm = null;

0 commit comments

Comments
 (0)