Skip to content

Commit

Permalink
preventing overridding some methods and classes using final
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Nov 29, 2018
1 parent 8beba97 commit d34407e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/EntityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait EntityTrait
{
use ObjectTrait;

public function __construct(Model $model, string $id, ?stdClass $data = null)
final public function __construct(Model $model, string $id, ?stdClass $data = null)
{
$this->model = $model;
$this->data = $data;
Expand All @@ -24,7 +24,7 @@ public function __construct(Model $model, string $id, ?stdClass $data = null)
$this->data->id = $id;
}

public function __set($name, $value) : void
final public function __set($name, $value) : void
{
if ($name === 'id') {
throw new OverridingIdentityOfEntityException('You can not change the "id" of an entity!');
Expand All @@ -35,12 +35,12 @@ public function __set($name, $value) : void
$this->data->{$name} = $value;
}

public function __unset($name)
final public function __unset($name)
{
unset($this->data->{$name});
}

public static function createFromJsonFile(string $jsonFilePath, string $id) : EntityInterface
final public static function createFromJsonFile(string $jsonFilePath, string $id) : EntityInterface
{
if (!file_exists($jsonFilePath)) {
throw new CouldNotFindJSONSchemaFileException(
Expand All @@ -51,17 +51,17 @@ public static function createFromJsonFile(string $jsonFilePath, string $id) : En
return self::createFromJson($json, $id);
}

public static function createFromJson(string $json, string $id) : EntityInterface
final public static function createFromJson(string $json, string $id) : EntityInterface
{
return new self(new Model($json), $id);
return new static(new Model($json), $id);
}

public function entityId() : string
final public function entityId() : string
{
return $this->data->id;
}

public function validatePartially(array $requiredFields) : bool
final public function validatePartially(array $requiredFields) : bool
{
$model = $this->model->getModel();
$model->required = $requiredFields;
Expand Down
6 changes: 3 additions & 3 deletions src/ObjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ trait ObjectTrait
*/
private $data;

public function __get($name)
final public function __get($name)
{
return $this->data->{$name};
}

public function __isset($name) : bool
final public function __isset($name) : bool
{
return property_exists($this->data, $name);
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public function equals($rightHandedObject) : bool
return (string) json_encode($this->data) === (string) json_encode($rightHandedObject);
}

public function jsonSerialize() : stdClass
final public function jsonSerialize() : stdClass
{
return $this->data;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ValueObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Selami\Entity\Exception\InvalidMethodNameException;
use function in_array;

class ValueObjectBuilder
final class ValueObjectBuilder
{
private $jsonSchema;
private $properties;
Expand Down
8 changes: 4 additions & 4 deletions src/ValueObjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait ValueObjectTrait
{
use ObjectTrait;

public function __construct(Model $model, stdClass $data)
final public function __construct(Model $model, stdClass $data)
{
$this->model = $model;
$this->data = $data;
Expand All @@ -29,7 +29,7 @@ final public function __unset($name)
throw new BadMethodCallException('Can\'t manipulate Immutable Object');
}

public static function createFromJsonFile(string $filePath, stdClass $data) : ValueObjectInterface
final public static function createFromJsonFile(string $filePath, stdClass $data) : ValueObjectInterface
{
if (!file_exists($filePath)) {
throw new InvalidArgumentException(sprintf('Model definition file (%s) does not exist!', $filePath));
Expand All @@ -38,8 +38,8 @@ public static function createFromJsonFile(string $filePath, stdClass $data) : Va
return self::createFromJson($json, $data);
}

public static function createFromJson(string $json, stdClass $data) : ValueObjectInterface
final public static function createFromJson(string $json, stdClass $data) : ValueObjectInterface
{
return new self(new Model($json), $data);
return new static(new Model($json), $data);
}
}

0 comments on commit d34407e

Please sign in to comment.