Skip to content

Commit

Permalink
add attributes remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Nov 27, 2023
1 parent 9cae8b3 commit 5a14a79
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 65 deletions.
4 changes: 3 additions & 1 deletion src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,10 @@ public function getCaption(): string

/**
* When field is used as expression, this method will be called.
* Universal way to convert ourselves to expression. Off-load implementation into persistence.
*
* Off-load implementation into persistence.
*/
#[\Override]
public function getDsqlExpression(Expression $expression): Expression
{
$this->getOwner()->assertHasPersistence();
Expand Down
9 changes: 2 additions & 7 deletions src/Field/SqlExpressionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,13 @@ class SqlExpressionField extends Field
/** @var string Specifies which field to use. */
public $field;

/**
* Should this field use alias?
* Expression fields always need alias.
*/
#[\Override]
public function useAlias(): bool
{
return true;
}

/**
* When field is used as expression, this method will be called.
*/
#[\Override]
public function getDsqlExpression(Expression $expression): Expression
{
$expr = $this->expr;
Expand Down
1 change: 1 addition & 0 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,7 @@ public function export(array $fields = null, string $keyField = null, bool $type
*
* @return \Traversable<static>
*/
#[\Override]
final public function getIterator(): \Traversable
{
return $this->createIteratorBy([]);
Expand Down
13 changes: 4 additions & 9 deletions src/Model/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,8 @@ public function isAnd(): bool
return $this->junction === self::AND;
}

/**
* Clears the compound condition from nested conditions.
*
* @return static
*/
public function clear()
#[\Override]

Check failure on line 146 in src/Model/Scope.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Return type (Atk4\Data\Model\Scope) of method Atk4\Data\Model\Scope::clear() should be covariant with return type ($this(Atk4\Data\Model\Scope\AbstractScope)) of method Atk4\Data\Model\Scope\AbstractScope::clear()

Check failure on line 146 in src/Model/Scope.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Return type (Atk4\Data\Model\Scope) of method Atk4\Data\Model\Scope::clear() should be covariant with return type ($this(Atk4\Data\Model\Scope\AbstractScope)) of method Atk4\Data\Model\Scope\AbstractScope::clear()
public function clear(): self
{
$this->elements = [];

Expand All @@ -169,10 +165,9 @@ public function simplify(): AbstractScope

/**
* Use De Morgan's laws to negate.
*
* @return static
*/
public function negate()
#[\Override]

Check failure on line 169 in src/Model/Scope.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Return type (Atk4\Data\Model\Scope) of method Atk4\Data\Model\Scope::negate() should be covariant with return type ($this(Atk4\Data\Model\Scope\AbstractScope)) of method Atk4\Data\Model\Scope\AbstractScope::negate()

Check failure on line 169 in src/Model/Scope.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Return type (Atk4\Data\Model\Scope) of method Atk4\Data\Model\Scope::negate() should be covariant with return type ($this(Atk4\Data\Model\Scope\AbstractScope)) of method Atk4\Data\Model\Scope\AbstractScope::negate()
public function negate(): self
{
$this->junction = $this->junction === self::OR ? self::AND : self::OR;

Expand Down
11 changes: 5 additions & 6 deletions src/Model/Scope/AbstractScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@ public function getModel(): ?Model
/**
* Empty the scope object.
*
* @return static
* @return $this
*/
abstract public function clear();
abstract public function clear(): self;

/**
* Negate the scope object
* e.g from '=' to '!='.
* Negate the scope object e.g. from '=' to '!='.
*
* @return static
* @return $this
*/
abstract public function negate();
abstract public function negate(): self;

/**
* Return if scope has any conditions.
Expand Down
6 changes: 4 additions & 2 deletions src/Model/Scope/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ public function isEmpty(): bool
return array_filter([$this->key, $this->operator, $this->value]) ? false : true;
}

public function clear()
#[\Override]

Check failure on line 267 in src/Model/Scope/Condition.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Return type (Atk4\Data\Model\Scope\Condition) of method Atk4\Data\Model\Scope\Condition::clear() should be covariant with return type ($this(Atk4\Data\Model\Scope\AbstractScope)) of method Atk4\Data\Model\Scope\AbstractScope::clear()

Check failure on line 267 in src/Model/Scope/Condition.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Return type (Atk4\Data\Model\Scope\Condition) of method Atk4\Data\Model\Scope\Condition::clear() should be covariant with return type ($this(Atk4\Data\Model\Scope\AbstractScope)) of method Atk4\Data\Model\Scope\AbstractScope::clear()
public function clear(): self
{
$this->key = null; // @phpstan-ignore-line
$this->operator = null;
Expand All @@ -273,7 +274,8 @@ public function clear()
return $this;
}

public function negate()
#[\Override]

Check failure on line 277 in src/Model/Scope/Condition.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Return type (Atk4\Data\Model\Scope\Condition) of method Atk4\Data\Model\Scope\Condition::negate() should be covariant with return type ($this(Atk4\Data\Model\Scope\AbstractScope)) of method Atk4\Data\Model\Scope\AbstractScope::negate()

Check failure on line 277 in src/Model/Scope/Condition.php

View workflow job for this annotation

GitHub Actions / Smoke (latest, StaticAnalysis)

Return type (Atk4\Data\Model\Scope\Condition) of method Atk4\Data\Model\Scope\Condition::negate() should be covariant with return type ($this(Atk4\Data\Model\Scope\AbstractScope)) of method Atk4\Data\Model\Scope\AbstractScope::negate()
public function negate(): self
{
if (isset(self::$operators[$this->operator]['negate'])) {
$this->operator = self::$operators[$this->operator]['negate'];
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Scope/RootScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getModel(): Model
}

#[\Override]
public function negate()
public function negate(): self
{
throw new Exception('Model scope cannot be negated');
}
Expand Down
4 changes: 1 addition & 3 deletions src/Persistence/Array_.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ private function saveRow(Model $model, array $rowData, $id): void
}
}

/**
* @param array<string, mixed> $defaults
*/
#[\Override]
public function add(Model $model, array $defaults = []): void
{
$defaults = array_merge([
Expand Down
4 changes: 1 addition & 3 deletions src/Persistence/Array_/Action/RenameColumnIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public function __construct(\Traversable $iterator, string $origName, string $ne
$this->newName = $newName;
}

/**
* @return array<string, mixed>
*/
#[\Override]
public function current(): array
{
$row = parent::current();
Expand Down
8 changes: 5 additions & 3 deletions src/Persistence/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ public function getConnection(): Connection
return $this->_connection;
}

/**
* Disconnect from database explicitly.
*/
#[\Override]
public function disconnect(): void
{
parent::disconnect();
Expand All @@ -96,11 +94,13 @@ public function atomic(\Closure $fx)
return $this->getConnection()->atomic($fx);
}

#[\Override]
public function getDatabasePlatform(): AbstractPlatform
{
return $this->getConnection()->getDatabasePlatform();
}

#[\Override]
public function add(Model $model, array $defaults = []): void
{
$defaults = array_merge([
Expand Down Expand Up @@ -547,6 +547,7 @@ private function assertExactlyOneRecordUpdated(Model $model, $idRaw, int $affect
/**
* @param array<scalar|Expressionable|null> $dataRaw
*/
#[\Override]
protected function insertRaw(Model $model, array $dataRaw)
{
$insert = $this->initQuery($model);
Expand Down Expand Up @@ -583,6 +584,7 @@ protected function insertRaw(Model $model, array $dataRaw)
/**
* @param array<scalar|Expressionable|null> $dataRaw
*/
#[\Override]
protected function updateRaw(Model $model, $idRaw, array $dataRaw): void
{
$update = $this->initQuery($model);
Expand Down
1 change: 1 addition & 0 deletions src/Persistence/Sql/DbalDriverMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function createDatabasePlatformForVersion($version): AbstractPlatform
/**
* @return AbstractSchemaManager<AbstractPlatform>
*/
#[\Override]
public function getSchemaManager(DbalConnection $connection, AbstractPlatform $platform): AbstractSchemaManager
{
if ($platform instanceof SQLitePlatform) {
Expand Down
20 changes: 5 additions & 15 deletions src/Persistence/Sql/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,26 @@ public function __construct($template = [], array $arguments = [])
/**
* @return $this
*/
#[\Override]
public function getDsqlExpression(self $expression): self
{
return $this;
}

/**
* @param int|string $offset
*/
#[\Override]
public function offsetExists($offset): bool
{
return array_key_exists($offset, $this->args['custom']);
}

/**
* @param int|string $offset
*
* @return mixed
*/
#[\Override]
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->args['custom'][$offset];
}

/**
* @param int|string|null $offset
* @param mixed $value The value to set
*/
#[\Override]
public function offsetSet($offset, $value): void
{
if ($offset === null) {
Expand All @@ -130,9 +122,7 @@ public function offsetSet($offset, $value): void
}
}

/**
* @param int|string $offset
*/
#[\Override]
public function offsetUnset($offset): void
{
unset($this->args['custom'][$offset]);
Expand Down
9 changes: 3 additions & 6 deletions src/Persistence/Sql/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ public function __debugInfo(): array
/**
* Renders query template. If the template is not explicitly use "select" mode.
*/
#[\Override]
public function render(): array
{
if ($this->template === null) {
Expand All @@ -971,6 +972,7 @@ public function render(): array
return parent::render();
}

#[\Override]
protected function renderNested(): array
{
if (isset($this->args['order']) && !isset($this->args['limit'])) {
Expand Down Expand Up @@ -1015,12 +1017,7 @@ public function mode($mode)
return $this;
}

/**
* Create Expression object with the same connection.
*
* @param string|array<string, mixed> $template
* @param array<int|string, mixed> $arguments
*/
#[\Override]
public function expr($template = [], array $arguments = []): Expression
{
$class = $this->expressionClass;
Expand Down
5 changes: 1 addition & 4 deletions src/Reference/ContainsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ abstract class ContainsBase extends Reference
/** @var string Required! We need table alias for internal use only. */
protected $tableAlias = 'tbl';

/**
* Reference\ContainsOne will also add a field corresponding
* to 'ourField' unless it exists of course.
*/
#[\Override]
protected function init(): void
{
parent::init();
Expand Down
1 change: 1 addition & 0 deletions src/Reference/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ protected function referenceOurValue(): Field
/**
* Returns referenced model with condition set.
*/
#[\Override]
public function ref(Model $ourModel, array $defaults = []): Model
{
$ourModel = $this->getOurModel($ourModel);
Expand Down
8 changes: 3 additions & 5 deletions src/Reference/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ class HasOne extends Reference
use Model\FieldPropertiesTrait;
use Model\JoinLinkTrait;

/**
* Reference\HasOne will also add a field corresponding
* to 'ourField' unless it exists.
*/
#[\Override]
protected function init(): void
{
parent::init();
Expand Down Expand Up @@ -73,11 +70,12 @@ protected function referenceOurValue(): Field
}

/**
* If our model is loaded, then return their model with respective record loaded.
* If our model is loaded, then return their model with respective loaded entity.
*
* If our model is not loaded, then return their model with condition set.
* This can happen in case of deep traversal $model->ref('Many')->ref('one_id'), for example.
*/
#[\Override]
public function ref(Model $ourModel, array $defaults = []): Model
{
$ourModel = $this->getOurModel($ourModel);
Expand Down

0 comments on commit 5a14a79

Please sign in to comment.