diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml
index 1a6e733..2a62ee6 100644
--- a/.github/workflows/coding-standards.yml
+++ b/.github/workflows/coding-standards.yml
@@ -9,4 +9,4 @@ jobs:
cs:
uses: ray-di/.github/.github/workflows/coding-standards.yml@v1
with:
- php_version: 8.3
+ php_version: 8.4
diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
index 7a2889e..644d1ca 100644
--- a/.github/workflows/continuous-integration.yml
+++ b/.github/workflows/continuous-integration.yml
@@ -9,5 +9,4 @@ jobs:
ci:
uses: ray-di/.github/.github/workflows/continuous-integration.yml@v1
with:
- old_stable: '["7.4", "8.0", "8.1", "8.2"]'
- current_stable: 8.3
+ current_stable: 8.4
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
index ffae3d5..3713270 100644
--- a/.github/workflows/static-analysis.yml
+++ b/.github/workflows/static-analysis.yml
@@ -9,5 +9,5 @@ jobs:
sa:
uses: ray-di/.github/.github/workflows/static-analysis.yml@v1
with:
- php_version: 8.3
+ php_version: 8.4
has_crc_config: false
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
deleted file mode 100644
index 72688a8..0000000
--- a/.scrutinizer.yml
+++ /dev/null
@@ -1,13 +0,0 @@
-filter:
- paths: ["src/*"]
-
-tools:
- php_sim: true
- php_pdepend: true
- php_analyzer: true
-build:
- nodes:
- analysis:
- tests:
- override:
- - php-scrutinizer-run --enable-security-analysis
diff --git a/composer.json b/composer.json
index 962a423..cc565e7 100644
--- a/composer.json
+++ b/composer.json
@@ -8,23 +8,20 @@
"description": "aura/sql module for Ray.Di",
"license": "MIT",
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.4",
"ext-pdo": "*",
- "ray/di": "^2.13.1",
- "ray/aop": "^2.10.4",
- "aura/sql": "^4.0 || ^5.0",
- "aura/sqlquery": "^2.7.1 || 3.x-dev",
+ "ray/di": "^2.18",
+ "ray/aop": "^2.17",
+ "aura/sql": "^6.0",
"pagerfanta/pagerfanta": "^3.5",
- "rize/uri-template": "^0.3.4 || ^0.4",
+ "rize/uri-template": "^0.4",
"doctrine/annotations": "^1.11 || ^2.0",
"psr/log": "^1.1 || ^2.0 || ^3.0",
- "symfony/polyfill-php81": "^1.24"
+ "aura/sqlquery": "^3.0"
},
"require-dev": {
- "phpunit/phpunit": "^9.5",
- "bamarni/composer-bin-plugin": "^1.4",
- "maglnet/composer-require-checker": "^3.0"
-
+ "phpunit/phpunit": "^11.5.6",
+ "bamarni/composer-bin-plugin": "^1.4"
},
"autoload": {
"psr-4": {
diff --git a/psalm.xml b/psalm.xml
index 7c0333d..a87272e 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -1,10 +1,10 @@
@@ -12,4 +12,14 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/AuraSqlDeleteInject.php b/src-deprecated/AuraSqlDeleteInject.php
similarity index 82%
rename from src/AuraSqlDeleteInject.php
rename to src-deprecated/AuraSqlDeleteInject.php
index ffd2766..4ffbff1 100644
--- a/src/AuraSqlDeleteInject.php
+++ b/src-deprecated/AuraSqlDeleteInject.php
@@ -7,14 +7,13 @@
use Aura\SqlQuery\Common\DeleteInterface;
use Ray\Di\Di\Inject;
+/** @deprecated Use constructor injection instead */
trait AuraSqlDeleteInject
{
/** @var DeleteInterface */
protected $delete;
- /**
- * @Inject
- */
+ /** @Inject */
#[Inject]
public function setAuraSqlDelete(DeleteInterface $delete): void
{
diff --git a/src/AuraSqlInject.php b/src-deprecated/AuraSqlInject.php
similarity index 80%
rename from src/AuraSqlInject.php
rename to src-deprecated/AuraSqlInject.php
index 4f408ea..9585bd0 100644
--- a/src/AuraSqlInject.php
+++ b/src-deprecated/AuraSqlInject.php
@@ -7,17 +7,13 @@
use Aura\Sql\ExtendedPdoInterface;
use Ray\Di\Di\Inject;
-/**
- * @codeCoverageIgnore
- */
+/** @deprecated Use constructor injection instead */
trait AuraSqlInject
{
/** @var ExtendedPdoInterface */
protected $pdo;
- /**
- * @Inject()
- */
+ /** @Inject() */
#[Inject]
public function setAuraSql(?ExtendedPdoInterface $pdo)
{
diff --git a/src/AuraSqlInsertInject.php b/src-deprecated/AuraSqlInsertInject.php
similarity index 82%
rename from src/AuraSqlInsertInject.php
rename to src-deprecated/AuraSqlInsertInject.php
index 7528d73..64b7d08 100644
--- a/src/AuraSqlInsertInject.php
+++ b/src-deprecated/AuraSqlInsertInject.php
@@ -7,14 +7,13 @@
use Aura\SqlQuery\Common\InsertInterface;
use Ray\Di\Di\Inject;
+/** @deprecated Use constructor injection instead */
trait AuraSqlInsertInject
{
/** @var InsertInterface */
protected $insert;
- /**
- * @Inject
- */
+ /** @Inject */
#[Inject]
public function setAuraSqlInsert(InsertInterface $insert): void
{
diff --git a/src/AuraSqlPagerInject.php b/src-deprecated/AuraSqlPagerInject.php
similarity index 85%
rename from src/AuraSqlPagerInject.php
rename to src-deprecated/AuraSqlPagerInject.php
index 6116496..76476a0 100644
--- a/src/AuraSqlPagerInject.php
+++ b/src-deprecated/AuraSqlPagerInject.php
@@ -7,14 +7,13 @@
use Ray\AuraSqlModule\Pagerfanta\AuraSqlPagerFactoryInterface;
use Ray\Di\Di\Inject;
+/** @deprecated Use constructor injection instead */
trait AuraSqlPagerInject
{
/** @var AuraSqlPagerFactoryInterface */
protected $pagerFactory;
- /**
- * @Inject
- */
+ /** @Inject */
#[Inject]
public function setAuraSqlPager(AuraSqlPagerFactoryInterface $pagerFactory): void
{
diff --git a/src/AuraSqlQueryPagerInject.php b/src-deprecated/AuraSqlQueryPagerInject.php
similarity index 86%
rename from src/AuraSqlQueryPagerInject.php
rename to src-deprecated/AuraSqlQueryPagerInject.php
index e0b08a2..7a4375b 100644
--- a/src/AuraSqlQueryPagerInject.php
+++ b/src-deprecated/AuraSqlQueryPagerInject.php
@@ -7,14 +7,13 @@
use Ray\AuraSqlModule\Pagerfanta\AuraSqlQueryPagerFactoryInterface;
use Ray\Di\Di\Inject;
+/** @deprecated Use constructor injection instead */
trait AuraSqlQueryPagerInject
{
/** @var AuraSqlQueryPagerFactoryInterface */
protected $queryPagerFactory;
- /**
- * @Inject
- */
+ /** @Inject */
#[Inject]
public function setAuraSqlQueryPager(AuraSqlQueryPagerFactoryInterface $queryPagerFactory): void
{
diff --git a/src/AuraSqlSelectInject.php b/src-deprecated/AuraSqlSelectInject.php
similarity index 82%
rename from src/AuraSqlSelectInject.php
rename to src-deprecated/AuraSqlSelectInject.php
index c4ba419..760bf09 100644
--- a/src/AuraSqlSelectInject.php
+++ b/src-deprecated/AuraSqlSelectInject.php
@@ -7,14 +7,13 @@
use Aura\SqlQuery\Common\SelectInterface;
use Ray\Di\Di\Inject;
+/** @deprecated Use constructor injection instead */
trait AuraSqlSelectInject
{
/** @var SelectInterface */
protected $select;
- /**
- * @Inject
- */
+ /** @Inject */
#[Inject]
public function setAuraSqlSelect(SelectInterface $select): void
{
diff --git a/src/AuraSqlUpdateInject.php b/src-deprecated/AuraSqlUpdateInject.php
similarity index 82%
rename from src/AuraSqlUpdateInject.php
rename to src-deprecated/AuraSqlUpdateInject.php
index 09328c4..de83ee8 100644
--- a/src/AuraSqlUpdateInject.php
+++ b/src-deprecated/AuraSqlUpdateInject.php
@@ -7,14 +7,13 @@
use Aura\SqlQuery\Common\UpdateInterface;
use Ray\Di\Di\Inject;
+/** @deprecated Use constructor injection instead */
trait AuraSqlUpdateInject
{
/** @var UpdateInterface */
protected $update;
- /**
- * @Inject
- */
+ /** @Inject */
#[Inject]
public function setAuraSqlUpdate(UpdateInterface $update): void
{
diff --git a/src/Annotation/AuraSqlQueryConfig.php b/src/Annotation/AuraSqlQueryConfig.php
index c13464f..bee11f5 100644
--- a/src/Annotation/AuraSqlQueryConfig.php
+++ b/src/Annotation/AuraSqlQueryConfig.php
@@ -17,14 +17,10 @@
#[Attribute(Attribute::TARGET_METHOD), Qualifier]
final class AuraSqlQueryConfig
{
- /** @var ?array */
- public $value;
-
/**
* @param array $value
*/
- public function __construct(?array $value = null)
+ public function __construct(public ?array $value = null)
{
- $this->value = $value;
}
}
diff --git a/src/Annotation/PagerViewOption.php b/src/Annotation/PagerViewOption.php
index 6ecad5a..60c7dea 100644
--- a/src/Annotation/PagerViewOption.php
+++ b/src/Annotation/PagerViewOption.php
@@ -12,16 +12,12 @@
* @Annotation
* @Target("METHOD")
* @Qualifier
- * @NamedArgumentConstructor()
+ * @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_METHOD), Qualifier]
final class PagerViewOption
{
- /** @var string */
- public $value;
-
- public function __construct(string $value)
+ public function __construct(public string $value)
{
- $this->value = $value;
}
}
diff --git a/src/Annotation/Read.php b/src/Annotation/Read.php
index 65915d6..6a03f9b 100644
--- a/src/Annotation/Read.php
+++ b/src/Annotation/Read.php
@@ -5,7 +5,7 @@
namespace Ray\AuraSqlModule\Annotation;
use Attribute;
-use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
+use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
use Ray\Di\Di\Qualifier;
/**
@@ -14,14 +14,10 @@
* @Qualifier
* @NamedArgumentConstructor
*/
-#[Attribute(Attribute::TARGET_METHOD), Qualifier]
+#[Attribute(Attribute::TARGET_METHOD|Attribute::TARGET_PARAMETER), Qualifier]
final class Read
{
- /** @var string */
- public $value;
-
- public function __construct(string $value)
+ public function __construct(public string $value = '')
{
- $this->value = $value;
}
}
diff --git a/src/Annotation/Transactional.php b/src/Annotation/Transactional.php
index 6026c8c..7442b95 100644
--- a/src/Annotation/Transactional.php
+++ b/src/Annotation/Transactional.php
@@ -5,27 +5,25 @@
namespace Ray\AuraSqlModule\Annotation;
use Attribute;
-use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
+use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
/**
* @Annotation
* @Target("METHOD")
- * @NamedArgumentConstructor()
+ * @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class Transactional
{
- /**
- * @var ?array
- * @deprecated
- */
- public $value;
-
/**
* @param array $value
*/
- public function __construct(array $value = ['pdo'])
+ public function __construct(
+ /**
+ * @deprecated
+ */
+ public array $value = ['pdo']
+ )
{
- $this->value = $value;
}
}
diff --git a/src/AuraSqlBaseModule.php b/src/AuraSqlBaseModule.php
index 7a731bb..d6a01b2 100644
--- a/src/AuraSqlBaseModule.php
+++ b/src/AuraSqlBaseModule.php
@@ -11,16 +11,13 @@
class AuraSqlBaseModule extends AbstractModule
{
- private string $dsn;
-
- public function __construct(string $dsnKey, ?AbstractModule $module = null)
+ public function __construct(private readonly string $dsn, ?AbstractModule $module = null)
{
- $this->dsn = $dsnKey;
parent::__construct($module);
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
protected function configure(): void
{
diff --git a/src/AuraSqlConnectionInterceptor.php b/src/AuraSqlConnectionInterceptor.php
index c335621..ae62c5e 100644
--- a/src/AuraSqlConnectionInterceptor.php
+++ b/src/AuraSqlConnectionInterceptor.php
@@ -17,25 +17,17 @@ class AuraSqlConnectionInterceptor implements MethodInterceptor
{
public const PROP = 'pdo';
- private ConnectionLocatorInterface $connectionLocator;
-
- /** @var string[] */
- private array $readsMethods = [];
-
- /**
- * @phpstan-param array $readMethods
- *
- * @Read("readMethods")
- */
- #[Read('readMethods')]
- public function __construct(ConnectionLocatorInterface $connectionLocator, array $readMethods)
- {
- $this->connectionLocator = $connectionLocator;
- $this->readsMethods = $readMethods;
+ /** @phpstan-param array $readsMethods */
+ public function __construct(
+ private readonly ConnectionLocatorInterface $connectionLocator,
+ /** @var string[] */
+ #[Read]
+ private readonly array $readsMethods
+ ) {
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
public function invoke(MethodInvocation $invocation)
{
diff --git a/src/AuraSqlEnvModule.php b/src/AuraSqlEnvModule.php
index 93e7fed..0fcbdff 100644
--- a/src/AuraSqlEnvModule.php
+++ b/src/AuraSqlEnvModule.php
@@ -8,44 +8,27 @@
class AuraSqlEnvModule extends AbstractModule
{
- private string $dsn;
- private string $username;
- private string $password;
- private string $slave;
-
- /** @var array */
- private array $options;
-
- /** @var array */
- private array $queries;
-
/**
- * @param string $dsnKey Env key for Data Source Name (DSN)
- * @param string $usernameKey Env key for Username for the DSN string
- * @param string $passwordKey Env key for Password for the DSN string
- * @param string $slaveKey Env key for Comma separated slave host list
- * @param array $options A key=>value array of driver-specific connection options
- * @param array $queries Queries to execute after the connection.
+ * @param string $dsn Env key for Data Source Name (DSN)
+ * @param string $username Env key for Username for the DSN string
+ * @param string $password Env key for Password for the DSN string
+ * @param string $slave Env key for Comma separated slave host list
+ * @param array $options A key=>value array of driver-specific connection options
+ * @param array $queries Queries to execute after the connection.
*/
public function __construct(
- string $dsnKey,
- string $usernameKey = '',
- string $passwordKey = '',
- string $slaveKey = '',
- array $options = [],
- array $queries = []
+ private readonly string $dsn,
+ private readonly string $username = '',
+ private readonly string $password = '',
+ private readonly string $slave = '',
+ private readonly array $options = [],
+ private readonly array $queries = []
) {
- $this->dsn = $dsnKey;
- $this->username = $usernameKey;
- $this->password = $passwordKey;
- $this->slave = $slaveKey;
- $this->options = $options;
- $this->queries = $queries;
parent::__construct();
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
protected function configure(): void
{
diff --git a/src/AuraSqlLocatorModule.php b/src/AuraSqlLocatorModule.php
index 81e7409..38c3745 100644
--- a/src/AuraSqlLocatorModule.php
+++ b/src/AuraSqlLocatorModule.php
@@ -16,37 +16,29 @@
class AuraSqlLocatorModule extends AbstractModule
{
- private ConnectionLocatorInterface $connectionLocator;
-
- /** @var string[] */
- private array $readMethods;
-
- /** @var string[] */
- private array $writeMethods;
-
/**
* @phpstan-param array $readMethods
* @phpstan-param array $writeMethods
*/
public function __construct(
- ConnectionLocatorInterface $connectionLocator,
- array $readMethods = [],
- array $writeMethods = [],
+ private readonly ConnectionLocatorInterface $connectionLocator,
+ /** @var string[] */
+ private readonly array $readMethods = [],
+ /** @var string[] */
+ private readonly array $writeMethods = [],
?AbstractModule $module = null
) {
- $this->connectionLocator = $connectionLocator;
- $this->readMethods = $readMethods;
- $this->writeMethods = $writeMethods;
parent::__construct($module);
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
protected function configure(): void
{
if ((bool) $this->readMethods && (bool) $this->writeMethods) {
$this->bind()->annotatedWith(Read::class)->toInstance($this->readMethods);
+ /** @psalm-suppress MissingDependency */
$this->bind()->annotatedWith(Write::class)->toInstance($this->writeMethods);
}
@@ -66,19 +58,17 @@ protected function installReadWriteConnection(): void
$this->bindInterceptor(
$this->matcher->any(),
$this->matcher->annotatedWith(ReadOnlyConnection::class),
- [AuraSqlSlaveDbInterceptor::class]
+ [AuraSqlSlaveDbInterceptor::class],
);
// @WriteConnection
$this->bindInterceptor(
$this->matcher->any(),
$this->matcher->annotatedWith(WriteConnection::class),
- [AuraSqlMasterDbInterceptor::class]
+ [AuraSqlMasterDbInterceptor::class],
);
}
- /**
- * @param string[] $methods
- */
+ /** @param string[] $methods */
private function installLocatorDb(array $methods): void
{
// locator db
@@ -87,13 +77,13 @@ private function installLocatorDb(array $methods): void
$this->matcher->logicalAnd(
new IsInMethodMatcher($methods),
$this->matcher->logicalNot(
- $this->matcher->annotatedWith(ReadOnlyConnection::class)
+ $this->matcher->annotatedWith(ReadOnlyConnection::class),
),
$this->matcher->logicalNot(
- $this->matcher->annotatedWith(Connection::class)
- )
+ $this->matcher->annotatedWith(Connection::class),
+ ),
),
- [AuraSqlConnectionInterceptor::class]
+ [AuraSqlConnectionInterceptor::class],
);
}
}
diff --git a/src/AuraSqlMasterDbInterceptor.php b/src/AuraSqlMasterDbInterceptor.php
index dbf4302..a1dfbaa 100644
--- a/src/AuraSqlMasterDbInterceptor.php
+++ b/src/AuraSqlMasterDbInterceptor.php
@@ -13,15 +13,12 @@ class AuraSqlMasterDbInterceptor implements MethodInterceptor
{
public const PROP = 'pdo';
- private ConnectionLocatorInterface $connectionLocator;
-
- public function __construct(ConnectionLocatorInterface $connectionLocator)
+ public function __construct(private readonly ConnectionLocatorInterface $connectionLocator)
{
- $this->connectionLocator = $connectionLocator;
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
public function invoke(MethodInvocation $invocation)
{
diff --git a/src/AuraSqlMasterModule.php b/src/AuraSqlMasterModule.php
index 27b7f9f..b2e96c4 100644
--- a/src/AuraSqlMasterModule.php
+++ b/src/AuraSqlMasterModule.php
@@ -11,44 +11,31 @@
class AuraSqlMasterModule extends AbstractModule
{
- private string $dsn;
- private string $user;
- private string $password;
-
- /** @var array */
- private array $options;
-
- /** @var array */
- private array $attributes;
-
/**
* @phpstan-param array $options
* @phpstan-param array $attributes
*/
public function __construct(
- string $dsnKey,
- string $user = '',
- string $passwordKey = '',
- array $options = [],
- array $attributes = [],
+ private readonly string $dsn,
+ private readonly string $user = '',
+ private readonly string $password = '',
+ /** @var array */
+ private readonly array $options = [],
+ /** @var array */
+ private readonly array $attributes = [],
?AbstractModule $module = null
) {
- $this->dsn = $dsnKey;
- $this->user = $user;
- $this->password = $passwordKey;
- $this->options = $options;
- $this->attributes = $attributes;
parent::__construct($module);
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
protected function configure(): void
{
$this->bind(ExtendedPdoInterface::class)->toConstructor(
ExtendedPdo::class,
- 'dsn=pdo_dsn,username=pdo_user,password=pdo_pass,options=pdo_option,attributes=pdo_attributes'
+ 'dsn=pdo_dsn,username=pdo_user,password=pdo_pass,options=pdo_option,attributes=pdo_attributes',
)->in(Scope::SINGLETON);
$this->bind()->annotatedWith('pdo_dsn')->toInstance($this->dsn);
$this->bind()->annotatedWith('pdo_user')->toInstance($this->user);
diff --git a/src/AuraSqlModule.php b/src/AuraSqlModule.php
index 5893395..269748e 100644
--- a/src/AuraSqlModule.php
+++ b/src/AuraSqlModule.php
@@ -13,44 +13,27 @@ class AuraSqlModule extends AbstractModule
{
public const PARSE_PDO_DSN_REGEX = '/(.*?):(?:(host|server)=.*?;)?(.*)/i';
- private string $dsn;
- private string $user;
- private string $password;
- private string $slave;
-
- /** @var array */
- private array $options;
-
- /** @var array */
- private array $queries;
-
/**
- * @param string $dsnKey Data Source Name (DSN)
- * @param string $user User name for the DSN string
- * @param string $passwordKey Password for the DSN string
- * @param string $slaveKey Comma separated slave host list
- * @param array $options A key=>value array of driver-specific connection options
+ * @param string $dsn Data Source Name (DSN)
+ * @param string $user User name for the DSN string
+ * @param string $password Password for the DSN string
+ * @param string $slave Comma separated slave host list
+ * @param array $options A key=>value array of driver-specific connection options
* @param array $queries
*/
public function __construct(
- string $dsnKey,
- string $user = '',
- string $passwordKey = '',
- string $slaveKey = '',
- array $options = [],
- array $queries = []
+ private readonly string $dsn,
+ private readonly string $user = '',
+ private readonly string $password = '',
+ private readonly string $slave = '',
+ private readonly array $options = [],
+ private readonly array $queries = []
) {
- $this->dsn = $dsnKey;
- $this->user = $user;
- $this->password = $passwordKey;
- $this->slave = $slaveKey;
- $this->options = $options;
- $this->queries = $queries;
parent::__construct();
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
protected function configure(): void
{
@@ -68,7 +51,7 @@ private function configureSingleDsn(): void
$this->bind()->annotatedWith('pdo_queries')->toInstance($this->queries);
$this->bind(ExtendedPdoInterface::class)->toConstructor(
ExtendedPdo::class,
- 'dsn=pdo_dsn,username=pdo_user,password=pdo_pass,options=pdo_options,queries=pdo_queries'
+ 'dsn=pdo_dsn,username=pdo_user,password=pdo_pass,options=pdo_options,queries=pdo_queries',
)->in(Scope::SINGLETON);
}
@@ -80,7 +63,7 @@ private function configureMasterSlaveDsn(): void
$this->password,
$this->slave,
$this->options,
- $this->queries
+ $this->queries,
);
$this->install(new AuraSqlReplicationModule($locator));
}
diff --git a/src/AuraSqlProfileModule.php b/src/AuraSqlProfileModule.php
index 8b24a26..31cbbe0 100644
--- a/src/AuraSqlProfileModule.php
+++ b/src/AuraSqlProfileModule.php
@@ -10,7 +10,7 @@
class AuraSqlProfileModule extends AbstractModule
{
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
protected function configure(): void
{
diff --git a/src/AuraSqlQueryDeleteProvider.php b/src/AuraSqlQueryDeleteProvider.php
index 36d33ca..90bd0ad 100644
--- a/src/AuraSqlQueryDeleteProvider.php
+++ b/src/AuraSqlQueryDeleteProvider.php
@@ -9,26 +9,21 @@
use Ray\AuraSqlModule\Annotation\AuraSqlQueryConfig;
use Ray\Di\ProviderInterface;
-/**
- * @implements ProviderInterface
- */
+/** @implements ProviderInterface */
class AuraSqlQueryDeleteProvider implements ProviderInterface
{
- private string $db;
-
/**
* @param string $db The database type
*
* @AuraSqlQueryConfig
*/
#[AuraSqlQueryConfig]
- public function __construct(string $db)
+ public function __construct(private readonly string $db)
{
- $this->db = $db;
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
public function get(): DeleteInterface
{
diff --git a/src/AuraSqlQueryInsertProvider.php b/src/AuraSqlQueryInsertProvider.php
index dd5d82e..d8946c7 100644
--- a/src/AuraSqlQueryInsertProvider.php
+++ b/src/AuraSqlQueryInsertProvider.php
@@ -9,26 +9,21 @@
use Ray\AuraSqlModule\Annotation\AuraSqlQueryConfig;
use Ray\Di\ProviderInterface;
-/**
- * @implements ProviderInterface
- */
+/** @implements ProviderInterface */
class AuraSqlQueryInsertProvider implements ProviderInterface
{
- private string $db;
-
/**
* @param string $db The database type
*
* @AuraSqlQueryConfig
*/
#[AuraSqlQueryConfig]
- public function __construct(string $db)
+ public function __construct(private readonly string $db)
{
- $this->db = $db;
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
public function get(): InsertInterface
{
diff --git a/src/AuraSqlQueryModule.php b/src/AuraSqlQueryModule.php
index 7b2f4f0..0e2961a 100644
--- a/src/AuraSqlQueryModule.php
+++ b/src/AuraSqlQueryModule.php
@@ -13,16 +13,13 @@
class AuraSqlQueryModule extends AbstractModule
{
- private string $db;
-
- public function __construct(string $db, ?AbstractModule $module = null)
+ public function __construct(private readonly string $db, ?AbstractModule $module = null)
{
- $this->db = $db;
parent::__construct($module);
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
protected function configure(): void
{
diff --git a/src/AuraSqlQuerySelectProvider.php b/src/AuraSqlQuerySelectProvider.php
index c358b11..9371bb0 100644
--- a/src/AuraSqlQuerySelectProvider.php
+++ b/src/AuraSqlQuerySelectProvider.php
@@ -9,26 +9,21 @@
use Ray\AuraSqlModule\Annotation\AuraSqlQueryConfig;
use Ray\Di\ProviderInterface;
-/**
- * @implements ProviderInterface
- */
+/** @implements ProviderInterface */
class AuraSqlQuerySelectProvider implements ProviderInterface
{
- private string $db;
-
/**
* @param string $db The database type
*
* @AuraSqlQueryConfig
*/
#[AuraSqlQueryConfig()]
- public function __construct($db)
+ public function __construct(private readonly string $db)
{
- $this->db = $db;
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
public function get(): SelectInterface
{
diff --git a/src/AuraSqlQueryUpdateProvider.php b/src/AuraSqlQueryUpdateProvider.php
index 9cd3cba..95af3a1 100644
--- a/src/AuraSqlQueryUpdateProvider.php
+++ b/src/AuraSqlQueryUpdateProvider.php
@@ -9,26 +9,21 @@
use Ray\AuraSqlModule\Annotation\AuraSqlQueryConfig;
use Ray\Di\ProviderInterface;
-/**
- * @implements ProviderInterface
- */
+/** @implements ProviderInterface */
class AuraSqlQueryUpdateProvider implements ProviderInterface
{
- private string $db;
-
/**
* @param string $db The database type
*
* @AuraSqlQueryConfig
*/
#[AuraSqlQueryConfig]
- public function __construct($db)
+ public function __construct(private readonly string $db)
{
- $this->db = $db;
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
public function get(): UpdateInterface
{
diff --git a/src/AuraSqlReplicationDbProvider.php b/src/AuraSqlReplicationDbProvider.php
index b131c47..4f79516 100644
--- a/src/AuraSqlReplicationDbProvider.php
+++ b/src/AuraSqlReplicationDbProvider.php
@@ -10,23 +10,17 @@
use Ray\Di\ProviderInterface;
use Ray\Di\SetContextInterface;
-use function assert;
-
-/**
- * @implements ProviderInterface
- */
+/** @implements ProviderInterface */
class AuraSqlReplicationDbProvider implements ProviderInterface, SetContextInterface
{
- private InjectorInterface $injector;
private string $context = '';
- public function __construct(InjectorInterface $injector)
+ public function __construct(private readonly InjectorInterface $injector)
{
- $this->injector = $injector;
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*
* @param string $context
*/
@@ -36,12 +30,11 @@ public function setContext($context): void
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
public function get(): ExtendedPdoInterface
{
$connectionLocator = $this->injector->getInstance(ConnectionLocatorInterface::class, $this->context);
- assert($connectionLocator instanceof ConnectionLocatorInterface);
$isGetRequest = isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET';
return $isGetRequest ? $connectionLocator->getRead() : $connectionLocator->getWrite();
diff --git a/src/AuraSqlReplicationModule.php b/src/AuraSqlReplicationModule.php
index aaaa18e..d6a8a7d 100644
--- a/src/AuraSqlReplicationModule.php
+++ b/src/AuraSqlReplicationModule.php
@@ -13,21 +13,16 @@
class AuraSqlReplicationModule extends AbstractModule
{
- private ConnectionLocatorInterface $connectionLocator;
- private string $qualifer;
-
public function __construct(
- ConnectionLocatorInterface $connectionLocator,
- string $qualifer = '',
+ private readonly ConnectionLocatorInterface $connectionLocator,
+ private readonly string $qualifer = '',
?AbstractModule $module = null
) {
- $this->connectionLocator = $connectionLocator;
- $this->qualifer = $qualifer;
parent::__construct($module);
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
protected function configure(): void
{
@@ -51,13 +46,13 @@ protected function installReadWriteConnection(): void
$this->bindInterceptor(
$this->matcher->any(),
$this->matcher->annotatedWith(ReadOnlyConnection::class),
- [AuraSqlSlaveDbInterceptor::class]
+ [AuraSqlSlaveDbInterceptor::class],
);
// @WriteConnection
$this->bindInterceptor(
$this->matcher->any(),
$this->matcher->annotatedWith(WriteConnection::class),
- [AuraSqlMasterDbInterceptor::class]
+ [AuraSqlMasterDbInterceptor::class],
);
}
}
diff --git a/src/AuraSqlSlaveDbInterceptor.php b/src/AuraSqlSlaveDbInterceptor.php
index e47447b..618b38c 100644
--- a/src/AuraSqlSlaveDbInterceptor.php
+++ b/src/AuraSqlSlaveDbInterceptor.php
@@ -16,15 +16,12 @@ class AuraSqlSlaveDbInterceptor implements MethodInterceptor
*/
public const PROP = 'pdo';
- private ConnectionLocatorInterface $connectionLocator;
-
- public function __construct(ConnectionLocatorInterface $connectionLocator)
+ public function __construct(private readonly ConnectionLocatorInterface $connectionLocator)
{
- $this->connectionLocator = $connectionLocator;
}
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*/
public function invoke(MethodInvocation $invocation)
{
diff --git a/src/Connection.php b/src/Connection.php
index 44edc7b..bbc8b0c 100644
--- a/src/Connection.php
+++ b/src/Connection.php
@@ -8,15 +8,6 @@
class Connection
{
- private string $dsn;
- private string $username;
- private string $password;
-
- /** @var array */
- private array $options;
-
- /** @var array */
- private array $queries;
private ?ExtendedPdo $pdo = null;
/**
@@ -24,17 +15,14 @@ class Connection
* @phpstan-param array $queries
*/
public function __construct(
- string $dsn,
- string $username = '',
- string $password = '',
- array $options = [],
- array $queries = []
+ private readonly string $dsn,
+ private readonly string $username = '',
+ private readonly string $password = '',
+ /** @var array */
+ private readonly array $options = [],
+ /** @var array */
+ private readonly array $queries = []
) {
- $this->dsn = $dsn;
- $this->username = $username;
- $this->password = $password;
- $this->options = $options;
- $this->queries = $queries;
}
public function __invoke(): ExtendedPdo
diff --git a/src/ConnectionLocatorFactory.php b/src/ConnectionLocatorFactory.php
index 3dccf47..eea5d1c 100644
--- a/src/ConnectionLocatorFactory.php
+++ b/src/ConnectionLocatorFactory.php
@@ -12,9 +12,7 @@
final class ConnectionLocatorFactory
{
- /**
- * @codeCoverageIgnore
- */
+ /** @codeCoverageIgnore */
private function __construct()
{
}
diff --git a/src/EnvConnection.php b/src/EnvConnection.php
index 06d3ab1..05ad715 100644
--- a/src/EnvConnection.php
+++ b/src/EnvConnection.php
@@ -14,38 +14,23 @@
final class EnvConnection
{
- private string $dsn;
- private string $username;
- private string $password;
-
- /** @var array */
- private array $options;
-
- /** @var array */
- private array $queries;
-
/** @var array */
private static array $pdo = [];
- private ?string $slave;
/**
* @phpstan-param array $options
* @phpstan-param array $queries
*/
public function __construct(
- string $dsn,
- ?string $slave,
- string $username = '',
- string $password = '',
- array $options = [],
- array $queries = []
+ private readonly string $dsn,
+ private readonly ?string $slave,
+ private readonly string $username = '',
+ private readonly string $password = '',
+ /** @var array */
+ private readonly array $options = [],
+ /** @var array */
+ private readonly array $queries = []
) {
- $this->dsn = $dsn;
- $this->slave = $slave;
- $this->username = $username;
- $this->password = $password;
- $this->options = $options;
- $this->queries = $queries;
}
public function __invoke(): ExtendedPdo
@@ -60,7 +45,7 @@ public function __invoke(): ExtendedPdo
(string) getenv($this->username),
(string) getenv($this->password),
$this->options,
- $this->queries
+ $this->queries,
);
return self::$pdo[$dsn];
@@ -80,9 +65,6 @@ private function getDsn(): string
return $this->changeHost((string) getenv($this->dsn), $slave);
}
- /**
- * @psalm-pure
- */
private function changeHost(string $dsn, string $host): string
{
preg_match(AuraSqlModule::PARSE_PDO_DSN_REGEX, $dsn, $parts);
diff --git a/src/IsInMethodMatcher.php b/src/IsInMethodMatcher.php
index 4f5a762..4a5c2d4 100644
--- a/src/IsInMethodMatcher.php
+++ b/src/IsInMethodMatcher.php
@@ -13,7 +13,7 @@
class IsInMethodMatcher extends AbstractMatcher
{
/**
- * {@inheritdoc}
+ * {@inheritDoc}
*
* @phpstan-param ReflectionClass