From 84002a4e612167d777c88f49fe87f137d8a1282c Mon Sep 17 00:00:00 2001 From: oscarotero Date: Sat, 25 Jul 2015 20:29:46 +0200 Subject: [PATCH] cs-fixer --- probas.php | 23 +++++----- src/BaseRow.php | 4 +- src/Entity.php | 30 ++++++------- src/Factory.php | 28 ++++++------ src/Queries/BaseQuery.php | 9 ++-- src/Queries/Mysql/Count.php | 22 ++++------ src/Queries/Mysql/DbTables.php | 10 ++--- src/Queries/Mysql/Delete.php | 24 +++++------ src/Queries/Mysql/Fields.php | 15 +++---- src/Queries/Mysql/Insert.php | 24 +++++------ src/Queries/Mysql/Select.php | 48 ++++++++++----------- src/Queries/Mysql/Update.php | 32 ++++++-------- src/Queries/Mysql/WhereTrait.php | 18 ++++---- src/Queries/QueryInterface.php | 16 +++---- src/Queries/Sqlite/CompiledOptionsTrait.php | 4 +- src/Queries/Sqlite/DbTables.php | 2 +- src/Queries/Sqlite/Delete.php | 8 ++-- src/Queries/Sqlite/Fields.php | 4 +- src/Queries/Sqlite/Insert.php | 2 +- src/Queries/Sqlite/Update.php | 8 ++-- src/Row.php | 6 +-- src/RowCollection.php | 5 +-- src/RowInterface.php | 4 +- src/SimpleCrud.php | 19 ++++---- src/autoloader.php | 2 +- tests/QueriesTest.php | 4 +- 26 files changed, 163 insertions(+), 208 deletions(-) diff --git a/probas.php b/probas.php index 56998f7..8c22ebc 100644 --- a/probas.php +++ b/probas.php @@ -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); @@ -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); - diff --git a/src/BaseRow.php b/src/BaseRow.php index 844231b..9a6cc9a 100644 --- a/src/BaseRow.php +++ b/src/BaseRow.php @@ -31,7 +31,7 @@ public function getDb() /** * @see RowInterface - * + * * {@inheritdoc} */ public function getAttribute($name) @@ -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 diff --git a/src/Entity.php b/src/Entity.php index 9ae4261..d4fba10 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -1,11 +1,8 @@ db = $db; @@ -57,12 +53,12 @@ public function __construct(SimpleCrud $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) @@ -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) @@ -87,9 +83,9 @@ public function offsetExists($offset) /** * Returns a row with a specific id - * + * * @see ArrayAccess - * + * * @return Row|null */ public function offsetGet($offset) @@ -101,7 +97,7 @@ public function offsetGet($offset) /** * Store a row with a specific id - * + * * @see ArrayAccess */ public function offsetSet($offset, $value) @@ -122,7 +118,7 @@ public function offsetSet($offset, $value) /** * Remove a row with a specific id - * + * * @see ArrayAccess */ public function offsetUnset($offset) @@ -145,9 +141,9 @@ public function getDb() /** * Returns an attribute - * + * * @param string $name - * + * * @return null|mixed */ public function getAttribute($name) @@ -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] = []; } @@ -262,7 +258,7 @@ public function prepareDataFromDatabase(array $data) * * @param array $data * @param bool $new - * + * * @return array */ public function prepareDataToDatabase(array $data, $new) diff --git a/src/Factory.php b/src/Factory.php index 3349997..eeee90c 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -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) @@ -45,9 +45,9 @@ public function entities($namespace) /** * Set the namespace for the queries classes - * + * * @param string $namespace - * + * * @return self */ public function queries($namespace) @@ -59,9 +59,9 @@ public function queries($namespace) /** * Set the namespace for the fields classes - * + * * @param string $namespace - * + * * @return self */ public function fields($namespace) @@ -73,9 +73,9 @@ public function fields($namespace) /** * Set the namespace for the Row classes - * + * * @param string $namespace - * + * * @return self */ public function rows($namespace) @@ -87,9 +87,9 @@ public function rows($namespace) /** * Set the namespace for the RowCollection classes - * + * * @param string $namespace - * + * * @return self */ public function rowCollections($namespace) @@ -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) @@ -236,7 +236,6 @@ public function getField(Entity $entity, $name) } } - /** * Creates a new instance of a Query for a entity * @@ -254,10 +253,9 @@ public function getQuery(Entity $entity, $name) } } - /** * Returns all tables in the database - * + * * @return array */ private function getTables() diff --git a/src/Queries/BaseQuery.php b/src/Queries/BaseQuery.php index ade4b19..d1ea94a 100644 --- a/src/Queries/BaseQuery.php +++ b/src/Queries/BaseQuery.php @@ -2,8 +2,6 @@ namespace SimpleCrud\Queries; use SimpleCrud\Entity; -use SimpleCrud\SimpleCrudException; -use PDOStatement; /** * Base class used by all queries @@ -14,7 +12,7 @@ abstract class BaseQuery implements QueryInterface /** * @see QueryInterface - * + * * {@inheritdoc} */ public static function getInstance(Entity $entity) @@ -24,7 +22,7 @@ public static function getInstance(Entity $entity) /** * Constructor - * + * * @param Entity $entity */ public function __construct(Entity $entity) @@ -34,7 +32,7 @@ public function __construct(Entity $entity) /** * Magic method to execute Entity's queries - * + * * @param string $name * @param array $arguments */ @@ -50,6 +48,5 @@ public function __call($name, $arguments) } throw new \Exception("Not valid function '{$fn_name}' in the entity '{$this->entity->name}'"); - } } diff --git a/src/Queries/Mysql/Count.php b/src/Queries/Mysql/Count.php index 11a9edb..f63e205 100644 --- a/src/Queries/Mysql/Count.php +++ b/src/Queries/Mysql/Count.php @@ -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; @@ -20,9 +17,9 @@ class Count extends BaseQuery /** * @see QueryInterface - * + * * $entity->count($where, $marks, $limit) - * + * * {@inheritdoc} */ public static function execute(Entity $entity, array $args) @@ -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) @@ -57,9 +53,9 @@ public function limit($limit) /** * Adds new marks to the query - * + * * @param array $marks - * + * * @return self */ public function marks(array $marks) @@ -71,7 +67,7 @@ public function marks(array $marks) /** * Run the query and return a statement with the result - * + * * @return PDOStatement */ public function run() @@ -84,7 +80,7 @@ public function run() /** * Run the query and return the value - * + * * @return integer */ public function get() @@ -96,7 +92,7 @@ public function get() /** * Build and return the query - * + * * @return string */ public function __toString() diff --git a/src/Queries/Mysql/DbTables.php b/src/Queries/Mysql/DbTables.php index 46458e6..fc06a68 100644 --- a/src/Queries/Mysql/DbTables.php +++ b/src/Queries/Mysql/DbTables.php @@ -1,10 +1,6 @@ delete($where, $marks, $limit) - * + * * {@inheritdoc} */ public static function execute(Entity $entity, array $args) @@ -43,9 +39,9 @@ public static function execute(Entity $entity, array $args) /** * Adds a LIMIT clause - * + * * @param integer $limit - * + * * @return self */ public function limit($limit) @@ -57,9 +53,9 @@ public function limit($limit) /** * Adds an offset to the LIMIT clause - * + * * @param integer $offset - * + * * @return self */ public function offset($offset) @@ -71,9 +67,9 @@ public function offset($offset) /** * Adds new marks to the query - * + * * @param array $marks - * + * * @return self */ public function marks(array $marks) @@ -85,7 +81,7 @@ public function marks(array $marks) /** * Run the query and return all values - * + * * @return PDOStatement */ public function run() @@ -95,7 +91,7 @@ public function run() /** * Build and return the query - * + * * @return string */ public function __toString() diff --git a/src/Queries/Mysql/Fields.php b/src/Queries/Mysql/Fields.php index d7d7c8c..b0c219f 100644 --- a/src/Queries/Mysql/Fields.php +++ b/src/Queries/Mysql/Fields.php @@ -2,12 +2,8 @@ namespace SimpleCrud\Queries\Mysql; use SimpleCrud\Queries\BaseQuery; -use SimpleCrud\RowCollection; -use SimpleCrud\Row; use SimpleCrud\Entity; -use SimpleCrud\SimpleCrudException; use PDOStatement; -use PDO; /** * Manages a database query to get the fields names in Mysql databases @@ -16,9 +12,9 @@ class Fields extends BaseQuery { /** * @see QueryInterface - * + * * $entity->fields() - * + * * {@inheritdoc} */ public static function execute(Entity $entity, array $args) @@ -26,10 +22,9 @@ public static function execute(Entity $entity, array $args) return self::getInstance($entity)->get(); } - /** * Run the query and return all values - * + * * @return PDOStatement */ public function run() @@ -39,7 +34,7 @@ public function run() /** * Run the query and return the fields - * + * * @return array */ public function get() @@ -57,7 +52,7 @@ public function get() /** * Build and return the query - * + * * @return string */ public function __toString() diff --git a/src/Queries/Mysql/Insert.php b/src/Queries/Mysql/Insert.php index 4eada58..556eb74 100644 --- a/src/Queries/Mysql/Insert.php +++ b/src/Queries/Mysql/Insert.php @@ -2,12 +2,8 @@ namespace SimpleCrud\Queries\Mysql; use SimpleCrud\Queries\BaseQuery; -use SimpleCrud\RowCollection; -use SimpleCrud\Row; use SimpleCrud\Entity; -use SimpleCrud\SimpleCrudException; use PDOStatement; -use PDO; /** * Manages a database insert query in Mysql databases @@ -19,9 +15,9 @@ class Insert extends BaseQuery /** * @see QueryInterface - * + * * $entity->insert($data, $duplications) - * + * * {@inheritdoc} */ public static function execute(Entity $entity, array $args) @@ -43,9 +39,9 @@ public static function execute(Entity $entity, array $args) /** * Set the data to update - * + * * @param array $data - * + * * @return self */ public function data(array $data) @@ -57,9 +53,9 @@ public function data(array $data) /** * Set true to handle duplications - * + * * @param boolean $handle - * + * * @return self */ public function duplications($handle = true) @@ -71,7 +67,7 @@ public function duplications($handle = true) /** * Run the query and return all values - * + * * @return PDOStatement */ public function run() @@ -87,7 +83,7 @@ public function run() /** * Run the query and return the id - * + * * @return integer */ public function get() @@ -99,7 +95,7 @@ public function get() /** * Build and return the query - * + * * @return string */ public function __toString() @@ -125,7 +121,7 @@ public function __toString() /** * Generates the data part of a UPDATE query * - * @param array $fields + * @param array $fields * * @return string */ diff --git a/src/Queries/Mysql/Select.php b/src/Queries/Mysql/Select.php index f500daa..b575e08 100644 --- a/src/Queries/Mysql/Select.php +++ b/src/Queries/Mysql/Select.php @@ -26,9 +26,9 @@ class Select extends BaseQuery /** * @see QueryInterface - * + * * $entity->select($where, $marks, $orderBy, $limit) - * + * * {@inheritdoc} */ public static function execute(Entity $entity, array $args) @@ -56,9 +56,9 @@ public static function execute(Entity $entity, array $args) /** * Adds new extra table to the query - * - * @param string $table - * + * + * @param string $table + * * @return self */ public function from($table) @@ -70,10 +70,10 @@ public function from($table) /** * Adds a WHERE according with the relation of other entity - * + * * @param RowInterface $row - * @param string $through - * + * @param string $through + * * @return self */ public function relatedWith(RowInterface $row, $through = null) @@ -99,10 +99,10 @@ public function relatedWith(RowInterface $row, $through = null) /** * Adds an ORDER BY clause - * + * * @param string $orderBy * @param string|null $direction - * + * * @return self */ public function orderBy($orderBy, $direction = null) @@ -118,9 +118,9 @@ public function orderBy($orderBy, $direction = null) /** * Adds a LIMIT clause - * + * * @param integer $limit - * + * * @return self */ public function limit($limit) @@ -132,9 +132,9 @@ public function limit($limit) /** * Adds an offset to the LIMIT clause - * + * * @param integer $offset - * + * * @return self */ public function offset($offset) @@ -146,11 +146,11 @@ public function offset($offset) /** * Adds a LEFT JOIN clause - * + * * @param Entity $entity * @param string $on * @param array|null $marks - * + * * @return self */ public function leftJoin(Entity $entity, $on = null, $marks = null) @@ -161,7 +161,7 @@ public function leftJoin(Entity $entity, $on = null, $marks = null) $this->leftJoin[] = [ 'entity' => $entity, - 'on' => $on + 'on' => $on, ]; if ($marks) { @@ -173,9 +173,9 @@ public function leftJoin(Entity $entity, $on = null, $marks = null) /** * Adds new marks to the query - * + * * @param array $marks - * + * * @return self */ public function marks(array $marks) @@ -187,7 +187,7 @@ public function marks(array $marks) /** * Run the query and return a statement with the result - * + * * @return PDOStatement */ public function run() @@ -200,12 +200,12 @@ public function run() /** * Run the query and return all values - * + * * @return RowCollection */ public function all() { - $statement= $this->run(); + $statement = $this->run(); $result = $this->entity->createCollection(); while (($row = $statement->fetch())) { @@ -217,7 +217,7 @@ public function all() /** * Run the query and return the first value - * + * * @return RowCollection */ public function one() @@ -235,7 +235,7 @@ public function one() /** * Build and return the query - * + * * @return string */ public function __toString() diff --git a/src/Queries/Mysql/Update.php b/src/Queries/Mysql/Update.php index e8fca10..9cf6145 100644 --- a/src/Queries/Mysql/Update.php +++ b/src/Queries/Mysql/Update.php @@ -2,12 +2,8 @@ namespace SimpleCrud\Queries\Mysql; use SimpleCrud\Queries\BaseQuery; -use SimpleCrud\RowCollection; -use SimpleCrud\Row; use SimpleCrud\Entity; -use SimpleCrud\SimpleCrudException; use PDOStatement; -use PDO; /** * Manages a database update query in Mysql databases @@ -15,16 +11,16 @@ class Update extends BaseQuery { use WhereTrait; - + protected $data = []; protected $limit; protected $offset; /** * @see QueryInterface - * + * * $entity->update($data, $where, $marks, $limit) - * + * * {@inheritdoc} */ public static function execute(Entity $entity, array $args) @@ -46,9 +42,9 @@ public static function execute(Entity $entity, array $args) /** * Set the data to update - * + * * @param array $data - * + * * @return self */ public function data(array $data) @@ -60,9 +56,9 @@ public function data(array $data) /** * Adds a LIMIT clause - * + * * @param integer $limit - * + * * @return self */ public function limit($limit) @@ -74,9 +70,9 @@ public function limit($limit) /** * Adds an offset to the LIMIT clause - * + * * @param integer $offset - * + * * @return self */ public function offset($offset) @@ -88,9 +84,9 @@ public function offset($offset) /** * Adds new marks to the query - * + * * @param array $marks - * + * * @return self */ public function marks(array $marks) @@ -102,7 +98,7 @@ public function marks(array $marks) /** * Run the query and return all values - * + * * @return PDOStatement */ public function run() @@ -118,7 +114,7 @@ public function run() /** * Build and return the query - * + * * @return string */ public function __toString() @@ -146,7 +142,7 @@ public function __toString() /** * Generates the data part of a UPDATE query * - * @param array $fields + * @param array $fields * * @return string */ diff --git a/src/Queries/Mysql/WhereTrait.php b/src/Queries/Mysql/WhereTrait.php index 6da1521..fbc0e1b 100644 --- a/src/Queries/Mysql/WhereTrait.php +++ b/src/Queries/Mysql/WhereTrait.php @@ -1,8 +1,6 @@ where("`{$this->entity->table}`.`{$field}` IN (:{$field})", [":{$field}" => $value]); } - + return $this->where("`{$this->entity->table}`.`{$field}` = :{$field}", [":{$field}" => $value]); } /** * Adds a WHERE id = :id clause - * + * * @param int|array $id - * + * * @return self */ public function byId($id) diff --git a/src/Queries/QueryInterface.php b/src/Queries/QueryInterface.php index 1fe1284..ee1972c 100644 --- a/src/Queries/QueryInterface.php +++ b/src/Queries/QueryInterface.php @@ -12,35 +12,35 @@ interface QueryInterface { /** * Creates a query instance - * + * * @param Entity $entity - * + * * @return QueryInterface */ public static function getInstance(Entity $entity); /** * Executes the query and return the result - * + * * @param Entity $entity * @param array $args - * + * * @throws SimpleCrudException - * + * * @return mixed */ public static function execute(Entity $entity, array $args); /** * Run the query and return a statement with the result - * + * * @return PDOStatement */ public function run(); - + /** * Build and return the query - * + * * @return string */ public function __toString(); diff --git a/src/Queries/Sqlite/CompiledOptionsTrait.php b/src/Queries/Sqlite/CompiledOptionsTrait.php index 952eae5..1f7f1ae 100644 --- a/src/Queries/Sqlite/CompiledOptionsTrait.php +++ b/src/Queries/Sqlite/CompiledOptionsTrait.php @@ -13,9 +13,9 @@ trait CompiledOptionsTrait /** * Check whether the sqlite has a compiled option - * + * * @param string $name - * + * * @return boolean */ public function hasCompiledOption($name) diff --git a/src/Queries/Sqlite/DbTables.php b/src/Queries/Sqlite/DbTables.php index bc78a2c..c2d5092 100644 --- a/src/Queries/Sqlite/DbTables.php +++ b/src/Queries/Sqlite/DbTables.php @@ -10,7 +10,7 @@ class DbTables extends Mysql\DbTables { /** * Build and return the query - * + * * @return string */ public function __toString() diff --git a/src/Queries/Sqlite/Delete.php b/src/Queries/Sqlite/Delete.php index d17028f..58e53cb 100644 --- a/src/Queries/Sqlite/Delete.php +++ b/src/Queries/Sqlite/Delete.php @@ -12,10 +12,10 @@ class Delete extends Mysql\Delete /** * Adds a LIMIT clause - * + * * @param integer $limit * @param boolean $force - * + * * @return self */ public function limit($limit, $force = false) @@ -29,10 +29,10 @@ public function limit($limit, $force = false) /** * Adds an offset to the LIMIT clause - * + * * @param integer $offset * @param boolean $force - * + * * @return self */ public function offset($offset, $force = false) diff --git a/src/Queries/Sqlite/Fields.php b/src/Queries/Sqlite/Fields.php index 17c1368..f8984ff 100644 --- a/src/Queries/Sqlite/Fields.php +++ b/src/Queries/Sqlite/Fields.php @@ -11,7 +11,7 @@ class Fields extends Mysql\Fields { /** * Run the query and return the fields - * + * * @return array */ public function get() @@ -27,7 +27,7 @@ public function get() /** * Build and return the query - * + * * @return string */ public function __toString() diff --git a/src/Queries/Sqlite/Insert.php b/src/Queries/Sqlite/Insert.php index 76b4e3b..80bbf40 100644 --- a/src/Queries/Sqlite/Insert.php +++ b/src/Queries/Sqlite/Insert.php @@ -10,7 +10,7 @@ class Insert extends Mysql\Insert { /** * Build and return the query - * + * * @return string */ public function __toString() diff --git a/src/Queries/Sqlite/Update.php b/src/Queries/Sqlite/Update.php index de5b7cc..fb0e328 100644 --- a/src/Queries/Sqlite/Update.php +++ b/src/Queries/Sqlite/Update.php @@ -12,10 +12,10 @@ class Update extends Mysql\Update /** * Adds a LIMIT clause - * + * * @param integer $limit * @param boolean $force - * + * * @return self */ public function limit($limit, $force = false) @@ -29,10 +29,10 @@ public function limit($limit, $force = false) /** * Adds an offset to the LIMIT clause - * + * * @param integer $offset * @param boolean $force - * + * * @return self */ public function offset($offset, $force = false) diff --git a/src/Row.php b/src/Row.php index c82c9fb..641ee3b 100644 --- a/src/Row.php +++ b/src/Row.php @@ -3,8 +3,6 @@ use JsonSerializable; -use SimpleCrud\Queries\QueryInterface; - /** * Stores the data of an entity row * @@ -17,7 +15,7 @@ class Row extends BaseRow implements JsonSerializable /** * Row constructor. * - * @param Entity $entity + * @param Entity $entity */ public function __construct(Entity $entity) { @@ -150,7 +148,7 @@ public function relateWith(RowInterface $row) /** * Set new values to the row. * - * @param array $data The new values + * @param array $data The new values * * @return $this */ diff --git a/src/RowCollection.php b/src/RowCollection.php index ca97840..9c7ee43 100644 --- a/src/RowCollection.php +++ b/src/RowCollection.php @@ -38,7 +38,7 @@ public function __call($name, $arguments) /** * Magic method to set properties to all rows - * + * * @see self::set() */ public function __set($name, $value) @@ -48,7 +48,7 @@ public function __set($name, $value) /** * Magic method to get properties from all rows - * + * * @see self::get() */ public function __get($name) @@ -228,7 +228,6 @@ public function set($name, $value) return $this; } - /** * Returns one or all values of the collections. * diff --git a/src/RowInterface.php b/src/RowInterface.php index 2ea3315..d3811b5 100644 --- a/src/RowInterface.php +++ b/src/RowInterface.php @@ -34,9 +34,9 @@ public function getDb(); /** * Returns an attribute - * + * * @param string $name - * + * * @return null|mixed */ public function getAttribute($name); diff --git a/src/SimpleCrud.php b/src/SimpleCrud.php index eee0406..48a87b5 100644 --- a/src/SimpleCrud.php +++ b/src/SimpleCrud.php @@ -1,12 +1,9 @@ data([ 'title' => 'Hello world', 'pubdate' => new Datetime(), - 'type' => 2 + 'type' => 2, ]); $this->assertEquals((string) $query, 'INSERT INTO `posts` (`title`, `pubdate`, `type`) VALUES (:title, :pubdate, :type)'); @@ -45,7 +45,7 @@ public function testUpdate() ->data([ 'title' => 'Hello world', 'pubdate' => new Datetime(), - 'type' => 2 + 'type' => 2, ]) ->where('id = 3') ->limit(1, true);