Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @internal annotations; simplify ScopeCarrierInterface and ConsumerInterface #260

Merged
merged 7 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand All @@ -12,4 +11,11 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedAttributeClass>
<errorLevel type="suppress">
<referencedClass name="JetBrains\PhpStorm\ExpectedValues" />
</errorLevel>
</UndefinedAttributeClass>
</issueHandlers>
</psalm>
15 changes: 0 additions & 15 deletions src/Command/Database/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,4 @@ public function execute(): void

parent::execute();
}

public function register(
string $key,
mixed $value,
int $stream = self::DATA
): void {
if ($stream !== self::SCOPE) {
return;
}
if (empty($value)) {
return;
}

$this->setScope($key, $value);
}
}
14 changes: 3 additions & 11 deletions src/Command/Database/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Cycle\ORM\Command\StoreCommand;
use Cycle\ORM\Command\Traits\ErrorTrait;
use Cycle\ORM\Command\Traits\ScopeTrait;
use Cycle\ORM\Context\ConsumerInterface;
use Cycle\ORM\Exception\CommandException;
use Cycle\ORM\Heap\State;
use Cycle\Database\DatabaseInterface;
Expand All @@ -17,7 +18,7 @@
*
* This is conditional command, it would not be executed when no fields are given!
*/
final class Update extends StoreCommand implements ScopeCarrierInterface
final class Update extends StoreCommand implements ScopeCarrierInterface, ConsumerInterface
{
use ErrorTrait;
use ScopeTrait;
Expand Down Expand Up @@ -98,17 +99,8 @@ public function execute(): void
parent::execute();
}

public function register(string $key, mixed $value, int $stream = self::DATA): void
public function register(string $key, mixed $value): void
{
if ($stream === self::SCOPE) {
if (empty($value)) {
return;
}

$this->setScope($key, $value);

return;
}
$this->state->register($key, $value);
}
}
3 changes: 1 addition & 2 deletions src/Command/ScopeCarrierInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

namespace Cycle\ORM\Command;

use Cycle\ORM\Context\ConsumerInterface;
use Cycle\ORM\Exception\CommandException;

/**
* Command indicates the ability to accept the forwarded scope values.
*/
interface ScopeCarrierInterface extends CommandInterface, ConsumerInterface
interface ScopeCarrierInterface extends CommandInterface
{
/**
* Wait for the scope value. Command must not be ready until the value come.
Expand Down
6 changes: 5 additions & 1 deletion src/Command/Traits/ErrorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

namespace Cycle\ORM\Command\Traits;

// describes why command has been locked up
/**
* Describes why command has been locked up
*
* @internal
*/
trait ErrorTrait
{
public function __toError()
Expand Down
6 changes: 6 additions & 0 deletions src/Command/Traits/ScopeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Cycle\ORM\Exception\CommandException;

/**
* @internal
*/
trait ScopeTrait
{
protected array $scope = [];
Expand Down Expand Up @@ -45,6 +48,9 @@ public function getAffectedRows(): int

public function setScope(string $key, mixed $value): void
{
if ($value === null) {
return;
}
$this->scope[$key] = $value;
// Indicate that context value is not required anymore.
unset($this->waitScope[$key]);
Expand Down
11 changes: 1 addition & 10 deletions src/Context/ConsumerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,19 @@

namespace Cycle\ORM\Context;

use JetBrains\PhpStorm\ExpectedValues;

/**
* Provides the ability to accept the forwarded key value.
*/
interface ConsumerInterface
{
// Value destinations.
public const DATA = 1;
public const SCOPE = 2;

/**
* Accept the value forwarded by another object.
*
* @param string $key Key name to accept the value.
* @param mixed $value The key value.
* @param int $stream One of the context types (data context, scope context).
*/
public function register(
string $key,
mixed $value,
#[ExpectedValues(valuesFromClass: self::class)]
int $stream = self::DATA
mixed $value
): void;
}
4 changes: 2 additions & 2 deletions src/Heap/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public function getInitialData(): array
return $this->data;
}

public function register(string $key, mixed $value, int $stream = self::DATA): void
public function register(string $key, mixed $value): void
{
$this->getState()->register($key, $value, $stream);
$this->getState()->register($key, $value);
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/Heap/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,8 @@ public function hasValue(string $key, bool $allowNull = true): bool
return array_key_exists($key, $this->data) || array_key_exists($key, $this->transactionData);
}

public function register(
string $key,
mixed $value,
int $stream = self::DATA
): void {
public function register(string $key, mixed $value): void
{
$this->freeWaitingField($key);

\Cycle\ORM\Transaction\Pool::DEBUG && print sprintf(
Expand Down
5 changes: 2 additions & 3 deletions src/Mapper/DatabaseMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Cycle\ORM\Command\Database\Delete;
use Cycle\ORM\Command\Database\Insert;
use Cycle\ORM\Command\Database\Update;
use Cycle\ORM\Context\ConsumerInterface;
use Cycle\ORM\EntityRegistryInterface;
use Cycle\ORM\Heap\Node;
use Cycle\ORM\Heap\State;
Expand Down Expand Up @@ -139,7 +138,7 @@ public function queueUpdate(object $entity, Node $node, State $state): CommandIn

foreach ($this->primaryKeys as $pk) {
// set update criteria right now
$update->register($pk, $fromData[$pk], ConsumerInterface::SCOPE);
$update->setScope($pk, $fromData[$pk]);
}

return $update;
Expand All @@ -154,7 +153,7 @@ public function queueDelete(object $entity, Node $node, State $state): CommandIn
$fromData = $node->getInitialData();
foreach ($this->primaryKeys as $pk) {
// set update criteria right now
$delete->register($pk, $fromData[$pk], ConsumerInterface::SCOPE);
$delete->setScope($pk, $fromData[$pk]);
}

return $delete;
Expand Down
3 changes: 3 additions & 0 deletions src/Mapper/Proxy/ClasslessProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Cycle\ORM\RelationMap;

/**
* @internal
*/
class ClasslessProxyFactory
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Mapper/Proxy/ClasslessProxyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Cycle\ORM\RelationMap;
use RuntimeException;

/**
* @internal
*/
trait ClasslessProxyTrait
{
public RelationMap $__cycle_orm_rel_map;
Expand Down
3 changes: 3 additions & 0 deletions src/Mapper/Proxy/EntityProxyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Cycle\ORM\RelationMap;
use RuntimeException;

/**
* @internal
*/
trait EntityProxyTrait
{
public RelationMap $__cycle_orm_rel_map;
Expand Down
3 changes: 3 additions & 0 deletions src/Mapper/Proxy/Hydrator/ClassPropertiesExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use ReflectionClass;
use ReflectionProperty;

/**
* @internal
*/
class ClassPropertiesExtractor
{
public const KEY_FIELDS = 'class';
Expand Down
3 changes: 3 additions & 0 deletions src/Mapper/Proxy/Hydrator/ClosureHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Cycle\ORM\Reference\ReferenceInterface;
use Cycle\ORM\RelationMap;

/**
* @internal
*/
class ClosureHydrator
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Mapper/Proxy/Hydrator/PropertyMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Cycle\ORM\Mapper\Proxy\Hydrator;

/**
* @internal
*/
class PropertyMap
{
public const PUBLIC_CLASS = '';
Expand Down
3 changes: 3 additions & 0 deletions src/Mapper/Proxy/ProxyEntityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Cycle\ORM\RelationMap;
use Doctrine\Instantiator\Instantiator;

/**
* @internal
*/
class ProxyEntityFactory
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Mapper/Traits/SingleTableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Cycle\ORM\SchemaInterface;

/**
* @internal
*/
trait SingleTableTrait
{
protected string $discriminator = '_type';
Expand Down
3 changes: 3 additions & 0 deletions src/Parser/CompositeTypecast.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Cycle\ORM\Parser;

/**
* @internal
*/
final class CompositeTypecast implements TypecastInterface
{
/** @var TypecastInterface[] */
Expand Down
2 changes: 2 additions & 0 deletions src/Parser/Traits/DuplicateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/**
* Trait provides ability for Node to ensure that given data is unique in selection. Primary key
* would be used to tie duplicate nodes together.
*
* @internal
*/
trait DuplicateTrait
{
Expand Down
3 changes: 3 additions & 0 deletions src/Parser/Typecast.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Cycle\Database\DatabaseInterface;
use Throwable;

/**
* @internal
*/
final class Typecast implements TypecastInterface
{
private const RULES = ['int', 'bool', 'float', 'datetime'];
Expand Down
3 changes: 3 additions & 0 deletions src/Relation/AbstractRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Cycle\ORM\SchemaInterface;
use Cycle\ORM\Select\SourceInterface;

/**
* @internal
*/
abstract class AbstractRelation implements ActiveRelationInterface, \Stringable
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Relation/ActiveRelationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/**
* Manages single branch type between parent entity and other objects.
*
* @internal
*/
interface ActiveRelationInterface extends RelationInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Relation/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Provides ability to link to the parent object.
* Will claim branch up to the parent object and it's relations. To disable
* branch walk-through use RefersTo relation.
*
* @internal
*/
class BelongsTo extends AbstractRelation implements DependencyInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Relation/DependencyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* Identical to RelationInterface but defines "left" side of the graph (relation to parent objects).
*
* @internal
*/
interface DependencyInterface extends RelationInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Relation/Embedded.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

/**
* Embeds one object to another.
*
* @internal
*/
final class Embedded implements SameRowRelationInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Relation/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

/**
* Provides the ability to own the collection of entities.
*
* @internal
*/
class HasMany extends AbstractRelation
{
Expand Down
2 changes: 2 additions & 0 deletions src/Relation/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

/**
* Provides the ability to own and forward context values to child entity.
*
* @internal
*/
class HasOne extends AbstractRelation
{
Expand Down
3 changes: 3 additions & 0 deletions src/Relation/ManyToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use SplObjectStorage;
use Traversable;

/**
* @internal
*/
class ManyToMany extends Relation\AbstractRelation
{
/** @var string[] */
Expand Down
3 changes: 3 additions & 0 deletions src/Relation/Morphed/BelongsToMorphed.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Cycle\ORM\Transaction\Pool;
use Cycle\ORM\Transaction\Tuple;

/**
* @internal
*/
class BelongsToMorphed extends BelongsTo
{
private string $morphKey;
Expand Down
Loading