diff --git a/src/Connect.php b/src/Connect.php index f216b3c..19a0b02 100644 --- a/src/Connect.php +++ b/src/Connect.php @@ -10,13 +10,11 @@ namespace nystudio107\connect; -use nystudio107\connect\models\Settings; -use nystudio107\connect\variables\ConnectVariable; - use Craft; use craft\base\Plugin; use craft\web\twig\variables\CraftVariable; - +use nystudio107\connect\models\Settings; +use nystudio107\connect\variables\ConnectVariable; use yii\base\Event; /** @@ -32,9 +30,9 @@ class Connect extends Plugin // ========================================================================= /** - * @var Connect + * @var ?Connect */ - public static $plugin; + public static ?Connect $plugin = null; // Public Properties // ========================================================================= @@ -44,27 +42,35 @@ class Connect extends Plugin */ public string $schemaVersion = '1.0.0'; + /** + * @var bool + */ + public bool $hasCpSection = false; + + /** + * @var bool + */ + public bool $hasCpSettings = false; + // Public Methods // ========================================================================= /** * @inheritdoc */ - public function init() + public function init(): void { parent::init(); self::$plugin = $this; - Event::on( CraftVariable::class, CraftVariable::EVENT_INIT, - function (Event $event) { + static function (Event $event) { /** @var CraftVariable $variable */ $variable = $event->sender; $variable->set('connect', ConnectVariable::class); } ); - Craft::info( Craft::t( 'connect', @@ -81,7 +87,7 @@ function (Event $event) { /** * @inheritdoc */ - protected function createSettingsModel(): ?\craft\base\Model + protected function createSettingsModel(): Settings { return new Settings(); } diff --git a/src/db/Query.php b/src/db/Query.php index 7e78e51..4a37a6b 100644 --- a/src/db/Query.php +++ b/src/db/Query.php @@ -23,9 +23,9 @@ class Query extends \yii\db\Query // ========================================================================= /** - * @var Connection the database connections + * @var ?Connection the database connections */ - public $db = null; + public ?Connection $db = null; // Public Methods // ========================================================================= @@ -37,7 +37,7 @@ public function createCommand($db = null) { return parent::createCommand($db ?? $this->db); } - + /** * @inheritdoc */ diff --git a/src/models/Settings.php b/src/models/Settings.php index e605ebd..0401cf5 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -26,7 +26,7 @@ class Settings extends Model /** * @var array the database connections */ - public $connections = []; + public array $connections = []; // Public Methods // ========================================================================= diff --git a/src/variables/ConnectVariable.php b/src/variables/ConnectVariable.php index f0be30f..9440ade 100644 --- a/src/variables/ConnectVariable.php +++ b/src/variables/ConnectVariable.php @@ -10,12 +10,10 @@ namespace nystudio107\connect\variables; +use Craft; use nystudio107\connect\Connect; use nystudio107\connect\db\Query; use nystudio107\connect\models\Settings; - -use Craft; - use yii\db\Connection; use yii\db\Exception; @@ -34,9 +32,9 @@ class ConnectVariable * * @param string $configName * - * @return null|Connection + * @return ?Connection */ - public function open(string $configName) + public function open(string $configName): ?Connection { $connection = null; $config = $this->getDbConfig($configName); @@ -56,11 +54,11 @@ public function open(string $configName) /** * Returns a new generic query. * - * @param null|Connection $connection + * @param ?Connection $connection * * @return Query */ - public function query($connection = null): Query + public function query(?Connection $connection = null): Query { return new Query([ 'db' => $connection, @@ -86,9 +84,9 @@ protected function getDbConfig(string $configName): array $dbConnection = $settings->connections[$configName]; $config = [ 'dsn' => "{$dbConnection['driver']}:" - ."host={$dbConnection['server']};" - ."dbname={$dbConnection['database']};" - ."port={$dbConnection['port']};", + . "host={$dbConnection['server']};" + . "dbname={$dbConnection['database']};" + . "port={$dbConnection['port']};", 'username' => $dbConnection['user'], 'password' => $dbConnection['password'], 'tablePrefix' => $dbConnection['tablePrefix'],