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

Codestyle and phpdoc fixes #84

Merged
merged 13 commits into from
Jan 19, 2016
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"name": "analogue/orm",
"description": "An intuitive Data Mapper ORM for PHP and Laravel",
"keywords": ["orm", "datamapper", "laravel",
"entity", "repository", "mapper"],
"keywords": [
"orm",
"datamapper",
"laravel",
"entity",
"repository",
"mapper"
],
"homepage": "http://github.com/analogueorm/analogue",
"license": "MIT",
"authors": [
Expand All @@ -29,5 +35,5 @@
}
},
"minimum-stability": "stable",
"prefer-stable":true
"prefer-stable": true
}
43 changes: 31 additions & 12 deletions src/Analogue.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Analogue\ORM;
<?php

namespace Analogue\ORM;

use Analogue\ORM\System\Manager;
use Illuminate\Events\Dispatcher;
Expand All @@ -10,21 +12,38 @@
/**
* This class is a proxy to the Manager class, which allows
* using Analogue outside of the Laravel framework.
*
* @mixin Manager
*/
class Analogue
{

/**
* @var self
*/
protected static $instance;

/**
* @var Manager
*/
protected static $manager;

/**
* @var Capsule
*/
protected static $capsule;

/**
* @var bool
*/
protected static $booted = false;

/**
* Analogue constructor.
* @param array $connection
*/
public function __construct(array $connection)
{
if (! static::$booted) {
if (!static::$booted) {
static::$capsule = new Capsule;

$this->addConnection($connection);
Expand Down Expand Up @@ -66,12 +85,12 @@ public function boot()
/**
* Add a connection array to Capsule
*
* @param array $config
* @param string $name
* @param array $config
* @param string $name
*/
public function addConnection($config, $name = 'default')
{
return static::$capsule->addConnection($config, $name);
static::$capsule->addConnection($config, $name);
}

/**
Expand All @@ -88,24 +107,24 @@ public function connection($name = null)
/**
* Dynamically handle static calls to the instance, Facade Style.
*
* @param string $method
* @param array $parameters
* @param string $method
* @param array $parameters
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
return call_user_func_array(array(static::$instance, $method), $parameters);
return call_user_func_array([static::$instance, $method], $parameters);
}

/**
* Dynamically handle calls to the Analogue Manager instance.
*
* @param string $method
* @param array $parameters
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
return call_user_func_array(array(static::$manager, $method), $parameters);
return call_user_func_array([static::$manager, $method], $parameters);
}
}
5 changes: 3 additions & 2 deletions src/AnalogueFacade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Analogue\ORM;
<?php

namespace Analogue\ORM;

use Illuminate\Support\Facades\Facade;

Expand All @@ -7,7 +9,6 @@
*/
class AnalogueFacade extends Facade
{

/**
* Get the registered name of the component.
*
Expand Down
5 changes: 3 additions & 2 deletions src/AnalogueServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Analogue\ORM;
<?php

namespace Analogue\ORM;

use Illuminate\Support\ServiceProvider;
use Analogue\ORM\System\Manager;
Expand All @@ -11,7 +13,6 @@
*/
class AnalogueServiceProvider extends ServiceProvider
{

/**
* Indicates if loading of the provider is deferred.
*
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

abstract class Command
{

/**
* The aggregated entity on which the command is executed
*
Expand All @@ -22,6 +21,11 @@ abstract class Command
*/
protected $query;

/**
* Command constructor.
* @param Aggregate $aggregate
* @param QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter $query
*/
public function __construct(Aggregate $aggregate, QueryAdapter $query)
{
$this->aggregate = $aggregate;
Expand Down
11 changes: 7 additions & 4 deletions src/Commands/Delete.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php namespace Analogue\ORM\Commands;
<?php

namespace Analogue\ORM\Commands;

use Analogue\ORM\Exceptions\MappingException;

class Delete extends Command
{

/**
* Execute the Delete Statement
*
* @return void
* @throws MappingException
* @throws \InvalidArgumentException
* @return false|void
*/
public function execute()
{
Expand All @@ -27,7 +30,7 @@ public function execute()
$id = $this->aggregate->getEntityId();

if (is_null($id)) {
throw new MappingException("Executed a delete command on an entity with 'null' as primary key");
throw new MappingException('Executed a delete command on an entity with "null" as primary key');
}

$this->query->where($keyName, '=', $id)->delete();
Expand Down
36 changes: 17 additions & 19 deletions src/Commands/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
namespace Analogue\ORM\Commands;

use Analogue\ORM\Mappable;
use Analogue\ORM\System\Mapper;
use Analogue\ORM\System\Manager;
use Analogue\ORM\EntityCollection;
use Analogue\ORM\Drivers\QueryAdapter;
use Analogue\ORM\System\Aggregate;
use Analogue\ORM\System\InternallyMappable;
use Analogue\ORM\System\Proxies\EntityProxy;
use Analogue\ORM\Exceptions\MappingException;
use Analogue\ORM\System\Proxies\ProxyInterface;
use Analogue\ORM\System\Proxies\CollectionProxy;

/**
Expand All @@ -20,11 +14,11 @@
*/
class Store extends Command
{

/**
* Persist the entity in the database
*
* @return void
* @throws \InvalidArgumentException
* @return false|mixed
*/
public function execute()
{
Expand All @@ -42,11 +36,11 @@ public function execute()
* We will test the entity for existence
* and run a creation if it doesn't exists
*/
if (! $this->aggregate->exists()) {
if (!$this->aggregate->exists()) {
if ($mapper->fireEvent('creating', $entity) === false) {
return false;
}

$this->insert();

$mapper->fireEvent('created', $entity, false);
Expand All @@ -70,33 +64,34 @@ public function execute()
$mapper->fireEvent('stored', $entity, false);

return $entity;
;
}

/**
* Run all operations that have to occur before actually
* storing the entity
*
* @throws \InvalidArgumentException
* @return void
*/
protected function preStoreProcess()
{
// Create any related object that doesn't exist in the database.
$localRelationships = $this->aggregate->getEntityMap()->getLocalRelationships();

$this->createRelatedEntities($localRelationships);
}

/**
* Check for existence and create non-existing related entities
*
* @param array
* @throws \InvalidArgumentException
* @return void
*/
protected function createRelatedEntities($relations)
{
$entitiesToCreate = $this->aggregate->getNonExistingRelated($relations);

foreach ($entitiesToCreate as $aggregate) {
$this->createStoreCommand($aggregate)->execute();
}
Expand All @@ -106,7 +101,7 @@ protected function createRelatedEntities($relations)
* Create a new store command
*
* @param Aggregate $aggregate
* @return void
* @return Store
*/
protected function createStoreCommand(Aggregate $aggregate)
{
Expand All @@ -120,6 +115,7 @@ protected function createStoreCommand(Aggregate $aggregate)
* Run all operations that have to occur after the entity
* is stored.
*
* @throws \InvalidArgumentException
* @return void
*/
protected function postStoreProcess()
Expand Down Expand Up @@ -147,7 +143,7 @@ protected function postStoreProcess()
// This should be move to the wrapper class
// so it's the same code for the entity builder
$aggregate->setProxies();

// Update Entity Cache
$aggregate->getMapper()->getEntityCache()->refresh($aggregate);
}
Expand All @@ -164,7 +160,7 @@ protected function updateDirtyRelated()
$attributes = $this->getAttributes();

foreach ($relations as $relation) {
if (! array_key_exists($relation, $attributes)) {
if (!array_key_exists($relation, $attributes)) {
continue;
}

Expand All @@ -181,7 +177,7 @@ protected function updateDirtyRelated()
if ($value instanceof CollectionProxy && $value->isLoaded()) {
$value = $value->getUnderlyingCollection();
}
if ($value instanceof CollectionProxy && ! $value->isLoaded()) {
if ($value instanceof CollectionProxy && !$value->isLoaded()) {
foreach ($value->getAddedItems() as $entity) {
$this->updateEntityIfDirty($entity);
}
Expand All @@ -190,7 +186,7 @@ protected function updateDirtyRelated()

if ($value instanceof EntityCollection) {
foreach ($value as $entity) {
if (! $this->createEntityIfNotExists($entity)) {
if (!$this->createEntityIfNotExists($entity)) {
$this->updateEntityIfDirty($entity);
}
}
Expand Down Expand Up @@ -231,6 +227,8 @@ protected function insert()
/**
* Run an update statement on the entity
*
* @throws \InvalidArgumentException
*
* @return void
*/
protected function update()
Expand All @@ -242,7 +240,7 @@ protected function update()
$query = $query->where($keyName, '=', $this->aggregate->getEntityId());

$dirtyAttributes = $this->aggregate->getDirtyRawAttributes();

if (count($dirtyAttributes) > 0) {
$query->update($dirtyAttributes);
}
Expand Down
12 changes: 10 additions & 2 deletions src/Drivers/CapsuleConnectionProvider.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?php namespace Analogue\ORM\Drivers;
<?php

namespace Analogue\ORM\Drivers;

use Illuminate\Database\Capsule\Manager as Capsule;

class CapsuleConnectionProvider
{

/**
* @var Capsule
*/
protected $capsule;

/**
* CapsuleConnectionProvider constructor.
* @param Capsule $capsule
*/
public function __construct(Capsule $capsule)
{
$this->capsule = $capsule;
Expand Down
8 changes: 4 additions & 4 deletions src/Drivers/DBAdapter.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php namespace Analogue\ORM\Drivers;
<?php

namespace Analogue\ORM\Drivers;

interface DBAdapter
{

/**
* Return's Driver specific Query Implementation
*
* @return \Analogue\ORM\Drivers\QueryAdapter
* @return \Analogue\ORM\Drivers\QueryAdapter|\Analogue\ORM\Drivers\IlluminateQueryAdapter
*/
public function getQuery();


/**
* Return the Date format used on this adapter
Expand Down
Loading