diff --git a/src/DefinitionBuilder.php b/src/DefinitionBuilder.php index 1030757..1782362 100644 --- a/src/DefinitionBuilder.php +++ b/src/DefinitionBuilder.php @@ -28,7 +28,7 @@ public static function get(string $modelClass): Definition /** * Builds a model definition given certain parameters. * - * @param string[] $ids + * @param string[] $ids * @param Property[] $properties */ public static function build(array $ids, array $properties, string $modelClass): Definition @@ -54,13 +54,13 @@ public static function build(array $ids, array $properties, string $modelClass): $relationType = $property['relation_type'] ?? null; if (isset($property['relation']) && !$relationType) { self::buildBelongsToLegacy($k, $property); - } elseif (isset($property['belongs_to']) || $relationType == Relationship::BELONGS_TO) { + } elseif (isset($property['belongs_to']) || Relationship::BELONGS_TO == $relationType) { self::buildBelongsTo($k, $property, $result); - } elseif (isset($property['has_one']) || $relationType == Relationship::HAS_ONE) { + } elseif (isset($property['has_one']) || Relationship::HAS_ONE == $relationType) { self::buildHasOne($property, $modelClass); - } elseif (isset($property['belongs_to_many']) || $relationType == Relationship::BELONGS_TO_MANY) { + } elseif (isset($property['belongs_to_many']) || Relationship::BELONGS_TO_MANY == $relationType) { self::buildBelongsToMany($property, $modelClass); - } elseif (isset($property['has_many']) || $relationType == Relationship::HAS_MANY) { + } elseif (isset($property['has_many']) || Relationship::HAS_MANY == $relationType) { self::buildHasMany($property, $modelClass); } elseif (isset($property['morphs_to'])) { self::buildPolymorphic($property, $k); @@ -82,9 +82,9 @@ public static function build(array $ids, array $properties, string $modelClass): return new Definition($ids, $result); } - ///////////////////////////////// + // /////////////////////////////// // Relationship Shortcuts - ///////////////////////////////// + // /////////////////////////////// /** * This is added for BC with older versions of pulsar diff --git a/src/Driver/AbstractDriver.php b/src/Driver/AbstractDriver.php index 983f370..2a37bc3 100644 --- a/src/Driver/AbstractDriver.php +++ b/src/Driver/AbstractDriver.php @@ -76,11 +76,11 @@ protected function prefixWhere(array $where, string $tablename): array // handles $where[property] = value if (!is_numeric($key)) { $return[] = [$this->prefixColumn($key, $tablename), $condition]; - // handles $where[] = [property, value, '='] + // handles $where[] = [property, value, '='] } elseif (is_array($condition)) { $condition[0] = $this->prefixColumn($condition[0], $tablename); $return[] = $condition; - // handles raw SQL - do nothing + // handles raw SQL - do nothing } else { $return[] = [$condition]; } diff --git a/src/Driver/DatabaseDriver.php b/src/Driver/DatabaseDriver.php index e818212..1c43f4f 100644 --- a/src/Driver/DatabaseDriver.php +++ b/src/Driver/DatabaseDriver.php @@ -13,7 +13,6 @@ use JAQB\ConnectionManager; use JAQB\Exception\JAQBException; -use JAQB\Query\SelectQuery; use JAQB\QueryBuilder; use PDOException; use PDOStatement; diff --git a/src/Driver/DbalDriver.php b/src/Driver/DbalDriver.php index b39ff85..b2b741e 100644 --- a/src/Driver/DbalDriver.php +++ b/src/Driver/DbalDriver.php @@ -222,9 +222,9 @@ public function min(Query $query, string $field): float return (float) $this->executeScalar($dbQuery, $model, $field); } - ////////////////////////// - /// Helpers - ////////////////////////// + // //////////////////////// + // / Helpers + // //////////////////////// /** * Builds a new select query. diff --git a/src/Errors.php b/src/Errors.php index 66dcf6d..8dd1a4f 100644 --- a/src/Errors.php +++ b/src/Errors.php @@ -138,9 +138,9 @@ public function __toString(): string return implode("\n", $this->all()); } - ////////////////////////// + // //////////////////////// // Helpers - ////////////////////////// + // //////////////////////// /** * Formats an incoming error message. @@ -162,18 +162,18 @@ private function parse(string $error, array $context): string return $this->getTranslator()->translate($error, $context, null); } - ////////////////////////// + // //////////////////////// // IteratorAggregate Interface - ////////////////////////// + // //////////////////////// public function getIterator(): Traversable { return new ArrayIterator($this->stack); } - ////////////////////////// + // //////////////////////// // Countable Interface - ////////////////////////// + // //////////////////////// /** * Get total number of models matching query. @@ -183,9 +183,9 @@ public function count(): int return count($this->stack); } - ///////////////////////////// + // /////////////////////////// // ArrayAccess Interface - ///////////////////////////// + // /////////////////////////// public function offsetExists($offset): bool { diff --git a/src/EventManager.php b/src/EventManager.php index 244e347..54a8ff7 100644 --- a/src/EventManager.php +++ b/src/EventManager.php @@ -11,7 +11,6 @@ */ class EventManager { - /** @var array */ private static array $dispatchers = []; /** diff --git a/src/Hydrator.php b/src/Hydrator.php index 8d4587d..ceed048 100644 --- a/src/Hydrator.php +++ b/src/Hydrator.php @@ -54,7 +54,7 @@ public static function hydrate(array $result, string|Model $modelClass, array $e if (isset($relationships[$id])) { if ($property->persisted) { $models[$j]->setRelation($k, $relationships[$id]); - // older style properties do not support this type of hydration + // older style properties do not support this type of hydration } else { $models[$j]->hydrateValue($k, $relationships[$id]); } @@ -67,7 +67,7 @@ public static function hydrate(array $result, string|Model $modelClass, array $e if (isset($relationships[$id])) { if ($property->persisted) { $models[$j]->setRelation($k, $relationships[$id]); - // older style properties do not support this type of hydration + // older style properties do not support this type of hydration } else { $models[$j]->hydrateValue($k, $relationships[$id]); } @@ -111,7 +111,7 @@ public static function hydrate(array $result, string|Model $modelClass, array $e /** * Hydrates the eager-loaded relationships for a given set of IDs. * - * @param bool $multiple when true will condense + * @param bool $multiple when true will condense * * @return Model[] */ diff --git a/src/Iterator.php b/src/Iterator.php index 59ced0c..c905fdd 100644 --- a/src/Iterator.php +++ b/src/Iterator.php @@ -56,9 +56,9 @@ public function getQuery(): Query return $this->query; } - ////////////////////////// + // //////////////////////// // Iterator Interface - ////////////////////////// + // //////////////////////// /** * Rewind the Iterator to the first element. @@ -122,9 +122,9 @@ public function valid(): bool return null !== $this->current(); } - ////////////////////////// + // //////////////////////// // Countable Interface - ////////////////////////// + // //////////////////////// /** * Get total number of models matching query. @@ -136,9 +136,9 @@ public function count(): int return $this->count; } - ////////////////////////// + // //////////////////////// // ArrayAccess Interface - ////////////////////////// + // //////////////////////// public function offsetExists($offset): bool { @@ -173,9 +173,9 @@ public function offsetUnset($offset) throw new \Exception('Cannot perform unset on immutable Iterator'); } - ////////////////////////// + // //////////////////////// // Private Methods - ////////////////////////// + // //////////////////////// /** * Load the next round of models. diff --git a/src/Model.php b/src/Model.php index c4874c8..48a844c 100644 --- a/src/Model.php +++ b/src/Model.php @@ -36,9 +36,9 @@ abstract class Model implements ArrayAccess { const DEFAULT_ID_NAME = 'id'; - ///////////////////////////// + // /////////////////////////// // Model visible variables - ///////////////////////////// + // /////////////////////////// protected array $_values = []; private array $_unsaved = []; @@ -47,9 +47,9 @@ abstract class Model implements ArrayAccess /** @var AbstractRelation[] */ private array $relationships = []; - ///////////////////////////// + // /////////////////////////// // Base model variables - ///////////////////////////// + // /////////////////////////// private static array $initialized = []; private static ?DriverInterface $driver = null; @@ -210,9 +210,9 @@ public function hasId(): bool return $this->hasId; } - ///////////////////////////// + // /////////////////////////// // Magic Methods - ///////////////////////////// + // /////////////////////////// /** * Converts the model into a string. @@ -297,9 +297,9 @@ public function __unset(string $name): void } } - ///////////////////////////// + // /////////////////////////// // ArrayAccess Interface - ///////////////////////////// + // /////////////////////////// public function offsetExists($offset): bool { @@ -331,9 +331,9 @@ public static function __callStatic($name, $parameters) return call_user_func_array([static::query(), $name], $parameters); } - ///////////////////////////// + // /////////////////////////// // Property Definitions - ///////////////////////////// + // /////////////////////////// /** * Gets the model definition. @@ -442,9 +442,9 @@ public static function getAccessor(string $property): ?string return self::$accessors[$k]; } - ///////////////////////////// + // /////////////////////////// // CRUD Operations - ///////////////////////////// + // /////////////////////////// /** * Gets the table name for storing this model. @@ -1104,9 +1104,9 @@ public function isDeleted(): bool return !$this->_persisted; } - ///////////////////////////// + // /////////////////////////// // Queries - ///////////////////////////// + // /////////////////////////// /** * Generates a new query instance. @@ -1227,9 +1227,9 @@ public function clearCache(): static return $this; } - ///////////////////////////// + // /////////////////////////// // Relationships - ///////////////////////////// + // /////////////////////////// /** * Gets the relationship manager for a property. @@ -1290,8 +1290,6 @@ private function saveRelationships(bool $usesTransactions): bool * scalar value or relationship. * * @internal - * - * @param $value */ public function hydrateValue(string $name, $value): void { @@ -1364,9 +1362,9 @@ public function clearRelation(string $k): static return $this; } - ///////////////////////////// + // /////////////////////////// // Events - ///////////////////////////// + // /////////////////////////// /** * Adds a listener to the model.creating and model.updating events. @@ -1454,9 +1452,9 @@ public static function deleted(callable $listener, int $priority = 0): void EventManager::listen(static::class, ModelDeleted::NAME, $listener, $priority); } - ///////////////////////////// + // /////////////////////////// // Validation - ///////////////////////////// + // /////////////////////////// /** * Gets the error stack for this model. diff --git a/src/Property.php b/src/Property.php index 04a4ccf..50ea897 100644 --- a/src/Property.php +++ b/src/Property.php @@ -43,9 +43,8 @@ public function __construct( ?string $has_many = null, public readonly ?string $enum_class = null, public readonly ?string $date_format = null, - ) - { - $this->hasDefault = $default !== self::MISSING_DEFAULT; + ) { + $this->hasDefault = self::MISSING_DEFAULT !== $default; $this->default = $this->hasDefault ? $default : null; // Relationship shortcuts diff --git a/src/Query.php b/src/Query.php index 5ea8a22..0fac8e2 100644 --- a/src/Query.php +++ b/src/Query.php @@ -133,9 +133,8 @@ public function getSort(): array * iii) where('balance', 100, '>') * iv) where('balance > 100'). * - * @param array|string $where - * @param mixed $value optional value - * @param string|null $condition optional condition + * @param mixed $value optional value + * @param string|null $condition optional condition * * @return $this */ @@ -181,7 +180,7 @@ public function getWhere(): array * to the ID of the model we are joining. * * @param Model|string $model model being joined - * @param string $column name of local property + * @param string $column name of local property * * @return $this */ diff --git a/src/Type.php b/src/Type.php index 5f51fa0..c2029fe 100644 --- a/src/Type.php +++ b/src/Type.php @@ -61,15 +61,15 @@ public static function cast(Property $property, mixed $value): mixed return $value; } - if ($type == self::ENUM) { + if (self::ENUM == $type) { return self::to_enum($value, (string) $property->enum_class); } - if ($type == self::DATE) { + if (self::DATE == $type) { return self::to_date($value, $property->date_format); } - if ($type == self::DATETIME) { + if (self::DATETIME == $type) { return self::to_datetime($value, $property->date_format); } diff --git a/tests/Driver/SerializeValueTestTrait.php b/tests/Driver/SerializeValueTestTrait.php index 018b5c1..beb104b 100644 --- a/tests/Driver/SerializeValueTestTrait.php +++ b/tests/Driver/SerializeValueTestTrait.php @@ -3,7 +3,6 @@ namespace Pulsar\Tests\Driver; use DateTimeImmutable; -use Pulsar\Driver\DatabaseDriver; use Pulsar\Property; use Pulsar\Tests\Enums\TestEnumInteger; use Pulsar\Tests\Enums\TestEnumString; @@ -49,4 +48,4 @@ public function testSerializeValueDateTime(): void $this->assertEquals('2023-01-08 01:02:03', $driver->serializeValue(new DateTimeImmutable('2023-01-08 01:02:03'), new Property(type: Type::DATETIME))); $this->assertEquals('1673139723', $driver->serializeValue(new DateTimeImmutable('2023-01-08 01:02:03'), new Property(date_format: 'U'))); } -} \ No newline at end of file +} diff --git a/tests/Enums/TestEnumInteger.php b/tests/Enums/TestEnumInteger.php index 6344974..ed158d2 100644 --- a/tests/Enums/TestEnumInteger.php +++ b/tests/Enums/TestEnumInteger.php @@ -7,4 +7,4 @@ enum TestEnumInteger: int case First = 1; case Second = 2; case Third = 3; -} \ No newline at end of file +} diff --git a/tests/Enums/TestEnumString.php b/tests/Enums/TestEnumString.php index b772591..4bebff8 100644 --- a/tests/Enums/TestEnumString.php +++ b/tests/Enums/TestEnumString.php @@ -7,4 +7,4 @@ enum TestEnumString: string case First = 'first'; case Second = 'second'; case Third = 'third'; -} \ No newline at end of file +} diff --git a/tests/IteratorTest.php b/tests/IteratorTest.php index f26b616..e9c92e0 100644 --- a/tests/IteratorTest.php +++ b/tests/IteratorTest.php @@ -169,7 +169,7 @@ public function testForeachChangingCount() if (51 == $i) { self::$count = 300; $this->assertCount(300, self::$iterator); - // simulate decreasing the # of records midway + // simulate decreasing the # of records midway } elseif (101 == $i) { self::$count = 26; $this->assertCount(26, self::$iterator); @@ -274,7 +274,7 @@ public function testQueryModelsMismatchCount() $numIterations = 0; foreach (self::$iterator as $model) { - $numIterations++; + ++$numIterations; } // when the end of the results is reached then the loop diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 7526696..3232bdb 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -1077,9 +1077,9 @@ public function testDirtyHasChangedCheck() $this->assertTrue($model->dirty('test', true)); } - ///////////////////////////// + // /////////////////////////// // CREATE - ///////////////////////////// + // /////////////////////////// public function testCreate() { @@ -1561,9 +1561,9 @@ public function testCreateEncrypted() $this->assertEquals('encrypted value', $newModel->encrypted); } - ///////////////////////////// + // /////////////////////////// // SET - ///////////////////////////// + // /////////////////////////// public function testSet() { @@ -1927,9 +1927,9 @@ public function testSetEncryptedNotModified() $this->assertEquals('encrypted value', $model->encrypted); } - ///////////////////////////// + // /////////////////////////// // DELETE - ///////////////////////////// + // /////////////////////////// public function testDelete() { @@ -2167,9 +2167,9 @@ public function testRestoreUpdatedEventFail() $this->assertFalse($model->restore()); } - ///////////////////////////// + // /////////////////////////// // Queries - ///////////////////////////// + // /////////////////////////// public function testQuery() { @@ -2262,9 +2262,9 @@ public function testFindOrFailNotFound() $this->assertFalse(TestModel::findOrFail(101)); } - ///////////////////////////// + // /////////////////////////// // Relationships - ///////////////////////////// + // /////////////////////////// public function testRelation() { @@ -2327,9 +2327,9 @@ public function testSetRelation() $this->assertEquals('2,3', $model->relation); } - ///////////////////////////// + // /////////////////////////// // Belongs To Relationship - ///////////////////////////// + // /////////////////////////// public function testGetPropertiesBelongsTo() { @@ -2578,9 +2578,9 @@ public function testGetFromDbBelongsTo() $this->assertEquals('Bob Loblaw', $invoice->customer->name); } - ///////////////////////////// + // /////////////////////////// // Storage - ///////////////////////////// + // /////////////////////////// public function testRefresh() { @@ -2624,9 +2624,9 @@ public function testPersisted() $this->assertTrue($model->persisted()); } - ///////////////////////////// + // /////////////////////////// // Validations - ///////////////////////////// + // /////////////////////////// public function testValid() { diff --git a/tests/Models/RelationshipTester.php b/tests/Models/RelationshipTester.php index 8919c57..3e9ac0b 100644 --- a/tests/Models/RelationshipTester.php +++ b/tests/Models/RelationshipTester.php @@ -13,7 +13,7 @@ protected static function getProperties(): array 'belongs_to_legacy' => new Property( relation: TestModel2::class, ), - 'belongs_to' => new Property( + 'belongs_to' => new Property( belongs_to: TestModel2::class, ), 'belongs_to_many' => new Property(