Skip to content

Commit

Permalink
cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Jul 25, 2015
1 parent 90bb543 commit 84002a4
Show file tree
Hide file tree
Showing 26 changed files with 163 additions and 208 deletions.
23 changes: 10 additions & 13 deletions probas.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@

var_dump($result);


return;
//ciencia ficción:

$pdo = new PDO();
$factory = Factory::create()
->entities('MyNamespace\\Entities')
->queries('MyNamespace\\Queries')
->fields('MyNamespace\\Fields')
->autocreate();
->entities('MyNamespace\\Entities')
->queries('MyNamespace\\Queries')
->fields('MyNamespace\\Fields')
->autocreate();

$db = new SimpleCrud($pdo, $factory);

Expand All @@ -32,16 +31,14 @@
$posts->select('pirolas verdes', true); // Query\Insert::exec() -> one

$posts
->querySelect()
->byId()
->relatedWith()
->where()
->limit(1)
->one();
->querySelect()
->byId()
->relatedWith()
->where()
->limit(1)
->one();

$posts->insert($data); // Query\Insert::exec()
$posts->insert()->data()->run();


$post = $posts->selectBy(1);

4 changes: 2 additions & 2 deletions src/BaseRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getDb()

/**
* @see RowInterface
*
*
* {@inheritdoc}
*/
public function getAttribute($name)
Expand All @@ -52,7 +52,7 @@ public function jsonSerialize()
/**
* Creates and return a Select query
*
* @param string $entity
* @param string $entity
* @param string|null $through
*
* @return QueryInterface
Expand Down
30 changes: 13 additions & 17 deletions src/Entity.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?php
namespace SimpleCrud;

use SimpleCrud\SimpleCrud;
use SimpleCrud\Queries\QueryInterface;
use ArrayAccess;
use PDOStatement;
use PDO;

/**
* Manages a database entity (table)
Expand Down Expand Up @@ -49,20 +46,19 @@ public static function getInstance($name, SimpleCrud $db)
return $entity;
}


public function __construct(SimpleCrud $db)
{
$this->db = $db;
}

/**
* Magic method to create queries related with this entity
*
*
* @param string $name
* @param array $arguments
*
*
* @throws SimpleCrudException
*
*
* @return QueryInterface|null
*/
public function __call($name, $arguments)
Expand All @@ -72,9 +68,9 @@ public function __call($name, $arguments)

/**
* Check if a row with a specific id exists
*
*
* @see ArrayAccess
*
*
* @return boolean
*/
public function offsetExists($offset)
Expand All @@ -87,9 +83,9 @@ public function offsetExists($offset)

/**
* Returns a row with a specific id
*
*
* @see ArrayAccess
*
*
* @return Row|null
*/
public function offsetGet($offset)
Expand All @@ -101,7 +97,7 @@ public function offsetGet($offset)

/**
* Store a row with a specific id
*
*
* @see ArrayAccess
*/
public function offsetSet($offset, $value)
Expand All @@ -122,7 +118,7 @@ public function offsetSet($offset, $value)

/**
* Remove a row with a specific id
*
*
* @see ArrayAccess
*/
public function offsetUnset($offset)
Expand All @@ -145,9 +141,9 @@ public function getDb()

/**
* Returns an attribute
*
*
* @param string $name
*
*
* @return null|mixed
*/
public function getAttribute($name)
Expand Down Expand Up @@ -232,7 +228,7 @@ public function prepareDataFromDatabase(array $data)

if (strpos($key, '.') !== false) {
list($name, $field) = explode('.', $key, 2);

if (!isset($joins[$name])) {
$joins[$name] = [];
}
Expand Down Expand Up @@ -262,7 +258,7 @@ public function prepareDataFromDatabase(array $data)
*
* @param array $data
* @param bool $new
*
*
* @return array
*/
public function prepareDataToDatabase(array $data, $new)
Expand Down
28 changes: 13 additions & 15 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function init(SimpleCrud $db)

/**
* Set the namespace for the entities classes
*
*
* @param string $namespace
*
*
* @return self
*/
public function entities($namespace)
Expand All @@ -45,9 +45,9 @@ public function entities($namespace)

/**
* Set the namespace for the queries classes
*
*
* @param string $namespace
*
*
* @return self
*/
public function queries($namespace)
Expand All @@ -59,9 +59,9 @@ public function queries($namespace)

/**
* Set the namespace for the fields classes
*
*
* @param string $namespace
*
*
* @return self
*/
public function fields($namespace)
Expand All @@ -73,9 +73,9 @@ public function fields($namespace)

/**
* Set the namespace for the Row classes
*
*
* @param string $namespace
*
*
* @return self
*/
public function rows($namespace)
Expand All @@ -87,9 +87,9 @@ public function rows($namespace)

/**
* Set the namespace for the RowCollection classes
*
*
* @param string $namespace
*
*
* @return self
*/
public function rowCollections($namespace)
Expand All @@ -101,9 +101,9 @@ public function rowCollections($namespace)

/**
* Set whether the entities are autocreated or not
*
*
* @param boolean $autocreate
*
*
* @return self
*/
public function autocreate($autocreate = true)
Expand Down Expand Up @@ -236,7 +236,6 @@ public function getField(Entity $entity, $name)
}
}


/**
* Creates a new instance of a Query for a entity
*
Expand All @@ -254,10 +253,9 @@ public function getQuery(Entity $entity, $name)
}
}


/**
* Returns all tables in the database
*
*
* @return array
*/
private function getTables()
Expand Down
9 changes: 3 additions & 6 deletions src/Queries/BaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
namespace SimpleCrud\Queries;

use SimpleCrud\Entity;
use SimpleCrud\SimpleCrudException;
use PDOStatement;

/**
* Base class used by all queries
Expand All @@ -14,7 +12,7 @@ abstract class BaseQuery implements QueryInterface

/**
* @see QueryInterface
*
*
* {@inheritdoc}
*/
public static function getInstance(Entity $entity)
Expand All @@ -24,7 +22,7 @@ public static function getInstance(Entity $entity)

/**
* Constructor
*
*
* @param Entity $entity
*/
public function __construct(Entity $entity)
Expand All @@ -34,7 +32,7 @@ public function __construct(Entity $entity)

/**
* Magic method to execute Entity's queries
*
*
* @param string $name
* @param array $arguments
*/
Expand All @@ -50,6 +48,5 @@ public function __call($name, $arguments)
}

throw new \Exception("Not valid function '{$fn_name}' in the entity '{$this->entity->name}'");

}
}
22 changes: 9 additions & 13 deletions src/Queries/Mysql/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
namespace SimpleCrud\Queries\Mysql;

use SimpleCrud\Queries\BaseQuery;
use SimpleCrud\RowCollection;
use SimpleCrud\Row;
use SimpleCrud\Entity;
use SimpleCrud\SimpleCrudException;
use PDOStatement;
use PDO;

Expand All @@ -20,9 +17,9 @@ class Count extends BaseQuery

/**
* @see QueryInterface
*
*
* $entity->count($where, $marks, $limit)
*
*
* {@inheritdoc}
*/
public static function execute(Entity $entity, array $args)
Expand All @@ -40,12 +37,11 @@ public static function execute(Entity $entity, array $args)
return $count->get();
}


/**
* Adds a LIMIT clause
*
*
* @param integer $limit
*
*
* @return self
*/
public function limit($limit)
Expand All @@ -57,9 +53,9 @@ public function limit($limit)

/**
* Adds new marks to the query
*
*
* @param array $marks
*
*
* @return self
*/
public function marks(array $marks)
Expand All @@ -71,7 +67,7 @@ public function marks(array $marks)

/**
* Run the query and return a statement with the result
*
*
* @return PDOStatement
*/
public function run()
Expand All @@ -84,7 +80,7 @@ public function run()

/**
* Run the query and return the value
*
*
* @return integer
*/
public function get()
Expand All @@ -96,7 +92,7 @@ public function get()

/**
* Build and return the query
*
*
* @return string
*/
public function __toString()
Expand Down
Loading

0 comments on commit 84002a4

Please sign in to comment.