From 147029292156eac93916c345cdb46eeb92f29fa5 Mon Sep 17 00:00:00 2001 From: oscarotero Date: Tue, 8 Sep 2015 21:18:17 +0200 Subject: [PATCH] fixes --- src/BaseRow.php | 2 ++ src/EntityFactory.php | 2 +- src/FieldFactory.php | 2 +- src/Queries/LimitTrait.php | 2 ++ src/Queries/Mysql/Select.php | 12 ++++++------ src/Queries/Sqlite/CompiledOptionsTrait.php | 2 ++ src/Queries/WhereExtendedTrait.php | 2 ++ src/Queries/WhereTrait.php | 2 ++ src/QueryFactory.php | 2 +- src/Row.php | 2 -- src/RowCollection.php | 6 ++---- src/SimpleCrud.php | 2 +- 12 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/BaseRow.php b/src/BaseRow.php index 4798653..04110d8 100644 --- a/src/BaseRow.php +++ b/src/BaseRow.php @@ -3,6 +3,8 @@ /** * Base class used by Row and RowCollection + * + * @property mixed $id */ abstract class BaseRow implements RowInterface { diff --git a/src/EntityFactory.php b/src/EntityFactory.php index d7bc631..8cb49aa 100644 --- a/src/EntityFactory.php +++ b/src/EntityFactory.php @@ -124,7 +124,7 @@ public function get($name) return new $class($name, $this->db, $queryFactory, $fieldFactory); } - } catch (Exception $exception) { + } catch (\Exception $exception) { throw new SimpleCrudException("Error getting the '{$name}' entity", 0, $exception); } diff --git a/src/FieldFactory.php b/src/FieldFactory.php index a5237d4..b8c20c3 100644 --- a/src/FieldFactory.php +++ b/src/FieldFactory.php @@ -79,7 +79,7 @@ public function get($name, $type = null) $class = $this->cachedTypes[$type] = $this->defaultType; return new $class(); - } catch (Exception $exception) { + } catch (\Exception $exception) { throw new SimpleCrudException("Error getting the '{$type}' field", 0, $exception); } } diff --git a/src/Queries/LimitTrait.php b/src/Queries/LimitTrait.php index 8cb25fe..5ec90e7 100644 --- a/src/Queries/LimitTrait.php +++ b/src/Queries/LimitTrait.php @@ -3,6 +3,8 @@ /** * Common function to manage LIMIT clause + * + * @property \SimpleCrud\Entity $entity */ trait LimitTrait { diff --git a/src/Queries/Mysql/Select.php b/src/Queries/Mysql/Select.php index a5e70df..a8c9fa8 100644 --- a/src/Queries/Mysql/Select.php +++ b/src/Queries/Mysql/Select.php @@ -162,7 +162,7 @@ public function __toString() $query .= ' '.static::buildFields($this->entity->name, array_keys($this->entity->fields)); foreach ($this->leftJoin as $join) { - $query .= ', '.static::buildFields($join['entity']->name, array_keys($join['entity']->fields), $join['entity']->name); + $query .= ', '.static::buildFields($join['entity']->name, array_keys($join['entity']->fields), true); } $query .= $this->fieldsToString(); @@ -191,19 +191,19 @@ public function __toString() /** * Generates the fields/tables part of a SELECT query * - * @param string $table - * @param array $fields - * @param string|null $rename + * @param string $table + * @param array $fields + * @param bool $rename * * @return string */ - protected static function buildFields($table, array $fields, $rename = null) + protected static function buildFields($table, array $fields, $rename = false) { $query = []; foreach ($fields as $field) { if ($rename) { - $query[] = "`{$table}`.`{$field}` as `{$rename}.{$field}`"; + $query[] = "`{$table}`.`{$field}` as `{$table}.{$field}`"; } else { $query[] = "`{$table}`.`{$field}`"; } diff --git a/src/Queries/Sqlite/CompiledOptionsTrait.php b/src/Queries/Sqlite/CompiledOptionsTrait.php index 1f7f1ae..c219721 100644 --- a/src/Queries/Sqlite/CompiledOptionsTrait.php +++ b/src/Queries/Sqlite/CompiledOptionsTrait.php @@ -6,6 +6,8 @@ /** * Manages a database select count query in Mysql databases + * + * @property \SimpleCrud\Entity $entity */ trait CompiledOptionsTrait { diff --git a/src/Queries/WhereExtendedTrait.php b/src/Queries/WhereExtendedTrait.php index 6ed3a12..66b3559 100644 --- a/src/Queries/WhereExtendedTrait.php +++ b/src/Queries/WhereExtendedTrait.php @@ -5,6 +5,8 @@ /** * Common function to manage WHERE clause + * + * @property \SimpleCrud\Entity $entity */ trait WhereExtendedTrait { diff --git a/src/Queries/WhereTrait.php b/src/Queries/WhereTrait.php index 1d65990..4b9e9e0 100644 --- a/src/Queries/WhereTrait.php +++ b/src/Queries/WhereTrait.php @@ -3,6 +3,8 @@ /** * Common function to manage WHERE clause + * + * @property \SimpleCrud\Entity $entity */ trait WhereTrait { diff --git a/src/QueryFactory.php b/src/QueryFactory.php index a8463ef..c04cdb9 100644 --- a/src/QueryFactory.php +++ b/src/QueryFactory.php @@ -73,7 +73,7 @@ public function get($name) return new $class($this->entity); } } - } catch (Exception $exception) { + } catch (\Exception $exception) { throw new SimpleCrudException("Error getting the '{$name}' query", 0, $exception); } diff --git a/src/Row.php b/src/Row.php index 4af99e8..0a1d897 100644 --- a/src/Row.php +++ b/src/Row.php @@ -5,8 +5,6 @@ /** * Stores the data of an entity row - * - * @property mixed $id */ class Row extends BaseRow implements JsonSerializable { diff --git a/src/RowCollection.php b/src/RowCollection.php index 7a32052..2b99712 100644 --- a/src/RowCollection.php +++ b/src/RowCollection.php @@ -7,8 +7,6 @@ /** * Stores a collection of rows - * - * @property array $id */ class RowCollection extends BaseRow implements ArrayAccess, Iterator, Countable { @@ -54,7 +52,7 @@ public function __get($name) $collection[] = $r; } } else { - $collection = $r; + $collection = $row; } } @@ -74,7 +72,7 @@ public function __get($name) //Returns values if ($first->has($name)) { - return $this->get($name, isset($arguments[0]) ? $arguments[0] : null); + return $this->get($name); } } diff --git a/src/SimpleCrud.php b/src/SimpleCrud.php index c9d56dd..c0de82f 100644 --- a/src/SimpleCrud.php +++ b/src/SimpleCrud.php @@ -8,7 +8,7 @@ class SimpleCrud { protected $connection; protected $inTransaction = false; - protected $factory; + protected $entityFactory; protected $entities = []; protected $attributes = [];