Skip to content

Commit

Permalink
Merge pull request #82 from neighborhoods/KOJO-151-state-transition-c…
Browse files Browse the repository at this point in the history
…hange-model-code

KOJO-151 | JobStateChange model code
  • Loading branch information
mucha55 authored Oct 2, 2019
2 parents 6ac27c7 + 8e2313b commit c43d79f
Show file tree
Hide file tree
Showing 55 changed files with 1,426 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Doctrine/Connection/Decorator/Repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- [createById, ["@=constant(\"\\\\Neighborhoods\\\\Kojo\\\\Doctrine\\\\Connection\\\\DecoratorInterface::ID_JOB\")"]]
- [createById, ["@=constant(\"\\\\Neighborhoods\\\\Kojo\\\\Doctrine\\\\Connection\\\\DecoratorInterface::ID_SCHEMA\")"]]
- [createById, ["@=constant(\"\\\\Neighborhoods\\\\Kojo\\\\Doctrine\\\\Connection\\\\DecoratorInterface::ID_STATUS\")"]]
- [createById, ["@=constant(\"\\\\Neighborhoods\\\\Kojo\\\\Doctrine\\\\Connection\\\\DecoratorInterface::ID_JOB_STATE_CHANGE\")"]]
doctrine.connection.decorator.repository:
alias: neighborhoods.kojo.doctrine.connection.decorator.repository
public: false
public: false
3 changes: 2 additions & 1 deletion src/Doctrine/Connection/DecoratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface DecoratorInterface
public const ID_STATUS = 'status';
public const ID_JOB = 'job';
public const ID_NON_TRANSACTIONAL = 'non_transactional';
public const ID_JOB_STATE_CHANGE = 'job_state_change';

public function getDoctrineConnection(): Connection;

Expand All @@ -24,4 +25,4 @@ public function setId(string $id): Decorator;
public function getId(): string;

public function setPDO(\PDO $pdo): DecoratorInterface;
}
}
46 changes: 46 additions & 0 deletions src/JobStateChange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo;

class JobStateChange implements JobStateChangeInterface
{
/** @var int */
protected $id;
/** @var JobStateChange\DataInterface */
protected $data;

public function getId() : int
{
if ($this->id === null) {
throw new \LogicException('JobStateChange id has not been set.');
}
return $this->id;
}

public function setId(int $id) : JobStateChangeInterface
{
if ($this->id !== null) {
throw new \LogicException('JobStateChange id is already set.');
}
$this->id = $id;
return $this;
}

public function getData() : JobStateChange\DataInterface
{
if ($this->data === null) {
throw new \LogicException('JobStateChange data has not been set.');
}
return $this->data;
}

public function setData(JobStateChange\DataInterface $data) : JobStateChangeInterface
{
if ($this->data !== null) {
throw new \LogicException('JobStateChange data is already set.');
}
$this->data = $data;
return $this;
}
}
8 changes: 8 additions & 0 deletions src/JobStateChange.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
neighborhoods.kojo.job_state_change:
class: Neighborhoods\Kojo\JobStateChange
public: false
shared: false
job_state_change:
alias: neighborhoods.kojo.job_state_change
public: false
46 changes: 46 additions & 0 deletions src/JobStateChange/AwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\JobStateChange;

use Neighborhoods\Kojo\JobStateChangeInterface;

/** @codeCoverageIgnore */
trait AwareTrait
{
protected $NeighborhoodsKojoJobStateChange;

public function setJobStateChange(JobStateChangeInterface $JobStateChange) : self
{
if ($this->hasJobStateChange()) {
throw new \LogicException('NeighborhoodsKojoJobStateChange is already set.');
}
$this->NeighborhoodsKojoJobStateChange = $JobStateChange;

return $this;
}

protected function getJobStateChange() : JobStateChangeInterface
{
if (!$this->hasJobStateChange()) {
throw new \LogicException('NeighborhoodsKojoJobStateChange is not set.');
}

return $this->NeighborhoodsKojoJobStateChange;
}

protected function hasJobStateChange() : bool
{
return isset($this->NeighborhoodsKojoJobStateChange);
}

protected function unsetJobStateChange() : self
{
if (!$this->hasJobStateChange()) {
throw new \LogicException('NeighborhoodsKojoJobStateChange is not set.');
}
unset($this->NeighborhoodsKojoJobStateChange);

return $this;
}
}
52 changes: 52 additions & 0 deletions src/JobStateChange/Builder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\JobStateChange;

use Neighborhoods\Kojo\JobStateChangeInterface;

class Builder implements BuilderInterface
{
use Factory\AwareTrait;
use Data\Builder\Factory\AwareTrait;

/** @var array */
protected $record;

public function build() : JobStateChangeInterface
{
$JobStateChange = $this->getJobStateChangeFactory()->create();
$record = $this->getRecord();

$JobStateChange->setId((int)$record[JobStateChangeInterface::PROP_ID]);
$JobStateChange->setData(
$this
->getJobStateChangeDataBuilderFactory()
->create()
->setRecord($record[JobStateChangeInterface::PROP_DATA])
->build()
);

return $JobStateChange;
}

protected function getRecord() : array
{
if ($this->record === null) {
throw new \LogicException('Builder record has not been set.');
}

return $this->record;
}

public function setRecord(array $record) : BuilderInterface
{
if ($this->record !== null) {
throw new \LogicException('Builder record is already set.');
}

$this->record = $record;

return $this;
}
}
11 changes: 11 additions & 0 deletions src/JobStateChange/Builder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
neighborhoods.kojo.job_state_change.builder:
class: Neighborhoods\Kojo\JobStateChange\Builder
public: false
shared: false
calls:
- [setJobStateChangeFactory, ['@job_state_change.factory']]
- [setJobStateChangeDataBuilderFactory, ['@job_state_change.data.builder.factory']]
job_state_change.builder:
alias: neighborhoods.kojo.job_state_change.builder
public: false
46 changes: 46 additions & 0 deletions src/JobStateChange/Builder/AwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\JobStateChange\Builder;

use Neighborhoods\Kojo\JobStateChange\BuilderInterface;

/** @codeCoverageIgnore */
trait AwareTrait
{
protected $NeighborhoodsKojoJobStateChangeBuilder;

public function setJobStateChangeBuilder(BuilderInterface $JobStateChangeBuilder) : self
{
if ($this->hasJobStateChangeBuilder()) {
throw new \LogicException('NeighborhoodsKojoJobStateChangeBuilder is already set.');
}
$this->NeighborhoodsKojoJobStateChangeBuilder = $JobStateChangeBuilder;

return $this;
}

protected function getJobStateChangeBuilder() : BuilderInterface
{
if (!$this->hasJobStateChangeBuilder()) {
throw new \LogicException('NeighborhoodsKojoJobStateChangeBuilder is not set.');
}

return $this->NeighborhoodsKojoJobStateChangeBuilder;
}

protected function hasJobStateChangeBuilder() : bool
{
return isset($this->NeighborhoodsKojoJobStateChangeBuilder);
}

protected function unsetJobStateChangeBuilder() : self
{
if (!$this->hasJobStateChangeBuilder()) {
throw new \LogicException('NeighborhoodsKojoJobStateChangeBuilder is not set.');
}
unset($this->NeighborhoodsKojoJobStateChangeBuilder);

return $this;
}
}
17 changes: 17 additions & 0 deletions src/JobStateChange/Builder/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\JobStateChange\Builder;

use Neighborhoods\Kojo\JobStateChange\BuilderInterface;

/** @codeCoverageIgnore */
class Factory implements FactoryInterface
{
use AwareTrait;

public function create() : BuilderInterface
{
return clone $this->getJobStateChangeBuilder();
}
}
10 changes: 10 additions & 0 deletions src/JobStateChange/Builder/Factory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
neighborhoods.kojo.job_state_change.builder.factory:
class: Neighborhoods\Kojo\JobStateChange\Builder\Factory
public: false
shared: true
calls:
- [setJobStateChangeBuilder, ['@job_state_change.builder']]
job_state_change.builder.factory:
alias: neighborhoods.kojo.job_state_change.builder.factory
public: false
46 changes: 46 additions & 0 deletions src/JobStateChange/Builder/Factory/AwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\JobStateChange\Builder\Factory;

use Neighborhoods\Kojo\JobStateChange\Builder\FactoryInterface;

/** @codeCoverageIgnore */
trait AwareTrait
{
protected $NeighborhoodsKojoJobStateChangeBuilderFactory;

public function setJobStateChangeBuilderFactory(FactoryInterface $JobStateChangeBuilderFactory) : self
{
if ($this->hasJobStateChangeBuilderFactory()) {
throw new \LogicException('NeighborhoodsKojoJobStateChangeBuilderFactory is already set.');
}
$this->NeighborhoodsKojoJobStateChangeBuilderFactory = $JobStateChangeBuilderFactory;

return $this;
}

protected function getJobStateChangeBuilderFactory() : FactoryInterface
{
if (!$this->hasJobStateChangeBuilderFactory()) {
throw new \LogicException('NeighborhoodsKojoJobStateChangeBuilderFactory is not set.');
}

return $this->NeighborhoodsKojoJobStateChangeBuilderFactory;
}

protected function hasJobStateChangeBuilderFactory() : bool
{
return isset($this->NeighborhoodsKojoJobStateChangeBuilderFactory);
}

protected function unsetJobStateChangeBuilderFactory() : self
{
if (!$this->hasJobStateChangeBuilderFactory()) {
throw new \LogicException('NeighborhoodsKojoJobStateChangeBuilderFactory is not set.');
}
unset($this->NeighborhoodsKojoJobStateChangeBuilderFactory);

return $this;
}
}
12 changes: 12 additions & 0 deletions src/JobStateChange/Builder/FactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\JobStateChange\Builder;

use Neighborhoods\Kojo\JobStateChange\BuilderInterface;

/** @codeCoverageIgnore */
interface FactoryInterface
{
public function create() : BuilderInterface;
}
13 changes: 13 additions & 0 deletions src/JobStateChange/BuilderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

namespace Neighborhoods\Kojo\JobStateChange;

use Neighborhoods\Kojo\JobStateChangeInterface;

interface BuilderInterface
{
public function build() : JobStateChangeInterface;

public function setRecord(array $record) : BuilderInterface;
}
Loading

0 comments on commit c43d79f

Please sign in to comment.