Commit 841008c4 authored by Guilherme Blanco's avatar Guilherme Blanco

[2.0] Coding Standards fixes, added missing docblocks, removed some...

[2.0] Coding Standards fixes, added missing docblocks, removed some dependencies from Common package (in Annotations component), etc.
parent 825cd7f4
...@@ -27,7 +27,8 @@ namespace Doctrine\Common\Annotations; ...@@ -27,7 +27,8 @@ namespace Doctrine\Common\Annotations;
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $ * @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
...@@ -52,14 +53,29 @@ class Annotation ...@@ -52,14 +53,29 @@ class Annotation
$this->$key = $value; $this->$key = $value;
} }
} }
/**
* Error handler for unknown property accessor in Annotation class.
*
* @param string $name Unknown property name
*/
public function __get($name) public function __get($name)
{ {
throw new \BadMethodCallException("Unknown annotation property '$name' on annotation '".get_class($this)."'."); throw new \BadMethodCallException(
sprintf("Unknown property '%s' on annotation '%s'.", $name, get_class($this))
);
} }
/**
* Error handler for unknown property mutator in Annotation class.
*
* @param string $name Unkown property name
* @param mixed $value Property value
*/
public function __set($name, $value) public function __set($name, $value)
{ {
throw new \BadMethodCallException("Unknown annotation property '$name' on annotation '".get_class($this)."'."); throw new \BadMethodCallException(
sprintf("Unknown property '%s' on annotation '%s'.", $name, get_class($this))
);
} }
} }
\ No newline at end of file
...@@ -27,20 +27,32 @@ namespace Doctrine\Common\Annotations; ...@@ -27,20 +27,32 @@ namespace Doctrine\Common\Annotations;
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $ * @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
*/ */
class AnnotationException extends \Doctrine\Common\CommonException class AnnotationException extends \Exception
{ {
/**
* Creates a new AnnotationException describing a Syntax error.
*
* @param string $message Exception message
* @return AnnotationException
*/
public static function syntaxError($message) public static function syntaxError($message)
{ {
return new self('[Syntax Error] ' . $message); return new self('[Syntax Error] ' . $message);
} }
/**
public static function semanticalError($message) * Creates a new AnnotationException describing a Semantical error.
*
* @param string $message Exception message
* @return AnnotationException
*/
public static function semanticalError($message)
{ {
return new self('[Semantical Error] ' . $message); return new self('[Semantical Error] ' . $message);
} }
......
...@@ -32,7 +32,7 @@ use \ReflectionClass, ...@@ -32,7 +32,7 @@ use \ReflectionClass,
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $ * @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de> * @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
...@@ -46,7 +46,7 @@ class AnnotationReader ...@@ -46,7 +46,7 @@ class AnnotationReader
* @var string * @var string
* @static * @static
*/ */
private static $CACHE_SALT = "@<Annot>"; private static $CACHE_SALT = '@<Annot>';
/** /**
* Annotations Parser * Annotations Parser
...@@ -56,15 +56,14 @@ class AnnotationReader ...@@ -56,15 +56,14 @@ class AnnotationReader
private $_parser; private $_parser;
/** /**
* Cache machanism to store processed Annotations * Cache mechanism to store processed Annotations
* *
* @var Doctrine\Common\Cache\Cache * @var Doctrine\Common\Cache\Cache
*/ */
private $_cache; private $_cache;
/** /**
* Constructor. Initializes a new AnnotationReader that uses the given * Constructor. Initializes a new AnnotationReader that uses the given Cache provider.
* Cache provider.
* *
* @param Cache $cache The cache provider to use. If none is provided, ArrayCache is used. * @param Cache $cache The cache provider to use. If none is provided, ArrayCache is used.
*/ */
...@@ -112,7 +111,7 @@ class AnnotationReader ...@@ -112,7 +111,7 @@ class AnnotationReader
return $data; return $data;
} }
$annotations = $this->_parser->parse($class->getDocComment(), "class ".$class->getName()); $annotations = $this->_parser->parse($class->getDocComment(), 'class ' . $class->getName());
$this->_cache->save($cacheKey, $annotations, null); $this->_cache->save($cacheKey, $annotations, null);
return $annotations; return $annotations;
...@@ -128,6 +127,7 @@ class AnnotationReader ...@@ -128,6 +127,7 @@ class AnnotationReader
public function getClassAnnotation(ReflectionClass $class, $annotation) public function getClassAnnotation(ReflectionClass $class, $annotation)
{ {
$annotations = $this->getClassAnnotations($class); $annotations = $this->getClassAnnotations($class);
return isset($annotations[$annotation]) ? $annotations[$annotation] : null; return isset($annotations[$annotation]) ? $annotations[$annotation] : null;
} }
...@@ -148,7 +148,7 @@ class AnnotationReader ...@@ -148,7 +148,7 @@ class AnnotationReader
return $data; return $data;
} }
$context = "property ".$property->getDeclaringClass()->getName()."::\$".$property->getName(); $context = 'property ' . $property->getDeclaringClass()->getName() . "::\$" . $property->getName();
$annotations = $this->_parser->parse($property->getDocComment(), $context); $annotations = $this->_parser->parse($property->getDocComment(), $context);
$this->_cache->save($cacheKey, $annotations, null); $this->_cache->save($cacheKey, $annotations, null);
...@@ -165,6 +165,7 @@ class AnnotationReader ...@@ -165,6 +165,7 @@ class AnnotationReader
public function getPropertyAnnotation(ReflectionProperty $property, $annotation) public function getPropertyAnnotation(ReflectionProperty $property, $annotation)
{ {
$annotations = $this->getPropertyAnnotations($property); $annotations = $this->getPropertyAnnotations($property);
return isset($annotations[$annotation]) ? $annotations[$annotation] : null; return isset($annotations[$annotation]) ? $annotations[$annotation] : null;
} }
...@@ -185,7 +186,7 @@ class AnnotationReader ...@@ -185,7 +186,7 @@ class AnnotationReader
return $data; return $data;
} }
$context = "method ".$method->getDeclaringClass()->getName()."::".$method->getName()."()"; $context = 'method ' . $method->getDeclaringClass()->getName() . '::' . $method->getName() . '()';
$annotations = $this->_parser->parse($method->getDocComment(), $context); $annotations = $this->_parser->parse($method->getDocComment(), $context);
$this->_cache->save($cacheKey, $annotations, null); $this->_cache->save($cacheKey, $annotations, null);
...@@ -202,6 +203,7 @@ class AnnotationReader ...@@ -202,6 +203,7 @@ class AnnotationReader
public function getMethodAnnotation(ReflectionMethod $method, $annotation) public function getMethodAnnotation(ReflectionMethod $method, $annotation)
{ {
$annotations = $this->getMethodAnnotations($method); $annotations = $this->getMethodAnnotations($method);
return isset($annotations[$annotation]) ? $annotations[$annotation] : null; return isset($annotations[$annotation]) ? $annotations[$annotation] : null;
} }
} }
\ No newline at end of file
...@@ -27,7 +27,8 @@ namespace Doctrine\Common\Annotations; ...@@ -27,7 +27,8 @@ namespace Doctrine\Common\Annotations;
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $ * @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
...@@ -80,7 +81,7 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -80,7 +81,7 @@ class Lexer extends \Doctrine\Common\Lexer
$newVal = $this->_getNumeric($value); $newVal = $this->_getNumeric($value);
// Checking numeric value // Checking numeric value
if ($newVal !== false){ if ($newVal !== false) {
$value = $newVal; $value = $newVal;
return (strpos($value, '.') !== false || stripos($value, 'e') !== false) return (strpos($value, '.') !== false || stripos($value, 'e') !== false)
...@@ -93,16 +94,34 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -93,16 +94,34 @@ class Lexer extends \Doctrine\Common\Lexer
return self::T_STRING; return self::T_STRING;
} else { } else {
switch (strtolower($value)) { switch (strtolower($value)) {
case '@': return self::T_AT; case '@':
case ',': return self::T_COMMA; return self::T_AT;
case '(': return self::T_OPEN_PARENTHESIS;
case ')': return self::T_CLOSE_PARENTHESIS; case ',':
case '{': return self::T_OPEN_CURLY_BRACES; return self::T_COMMA;
case '(':
return self::T_OPEN_PARENTHESIS;
case ')':
return self::T_CLOSE_PARENTHESIS;
case '{':
return self::T_OPEN_CURLY_BRACES;
case '}': return self::T_CLOSE_CURLY_BRACES; case '}': return self::T_CLOSE_CURLY_BRACES;
case '=': return self::T_EQUALS; case '=':
case '\\': return self::T_NAMESPACE_SEPARATOR; return self::T_EQUALS;
case 'true': return self::T_TRUE;
case 'false': return self::T_FALSE; case '\\':
return self::T_NAMESPACE_SEPARATOR;
case 'true':
return self::T_TRUE;
case 'false':
return self::T_FALSE;
default: default:
if (ctype_alpha($value[0]) || $value[0] === '_') { if (ctype_alpha($value[0]) || $value[0] === '_') {
return self::T_IDENTIFIER; return self::T_IDENTIFIER;
...@@ -126,6 +145,7 @@ class Lexer extends \Doctrine\Common\Lexer ...@@ -126,6 +145,7 @@ class Lexer extends \Doctrine\Common\Lexer
if ( ! is_scalar($value)) { if ( ! is_scalar($value)) {
return false; return false;
} }
// Checking for valid numeric numbers: 1.234, -1.234e-2 // Checking for valid numeric numbers: 1.234, -1.234e-2
if (is_numeric($value)) { if (is_numeric($value)) {
return $value; return $value;
......
...@@ -27,11 +27,11 @@ namespace Doctrine\Common\Annotations; ...@@ -27,11 +27,11 @@ namespace Doctrine\Common\Annotations;
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
* @version $Revision: 3938 $ * @version $Revision$
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class Parser class Parser
{ {
...@@ -173,9 +173,10 @@ class Parser ...@@ -173,9 +173,10 @@ class Parser
$message .= "'{$token['value']}' at position {$token['position']}"; $message .= "'{$token['value']}' at position {$token['position']}";
} }
if(strlen($this->_context)) { if (strlen($this->_context)) {
$message .= ' in '.$this->_context; $message .= ' in ' . $this->_context;
} }
$message .= '.'; $message .= '.';
throw AnnotationException::syntaxError($message); throw AnnotationException::syntaxError($message);
...@@ -411,6 +412,7 @@ class Parser ...@@ -411,6 +412,7 @@ class Parser
foreach ($values as $value) { foreach ($values as $value) {
list ($key, $val) = $value; list ($key, $val) = $value;
if ($key !== null) { if ($key !== null) {
$array[$key] = $val; $array[$key] = $val;
} else { } else {
......
...@@ -440,7 +440,8 @@ class EntityManager ...@@ -440,7 +440,8 @@ class EntityManager
* *
* @param object $entity The entity to copy. * @param object $entity The entity to copy.
* @return object The new entity. * @return object The new entity.
* @todo Implementation or remove. * @todo Implementation need. This is necessary since $e2 = clone $e1; throws an E_FATAL when access anything on $e:
* Fatal error: Maximum function nesting level of '100' reached, aborting!
*/ */
public function copy($entity, $deep = false) public function copy($entity, $deep = false)
{ {
......
...@@ -203,12 +203,15 @@ class Parser ...@@ -203,12 +203,15 @@ class Parser
// Process any deferred validations of some nodes in the AST. // Process any deferred validations of some nodes in the AST.
// This also allows post-processing of the AST for modification purposes. // This also allows post-processing of the AST for modification purposes.
$this->_processDeferredIdentificationVariables(); $this->_processDeferredIdentificationVariables();
if ($this->_deferredPartialObjectExpressions) { if ($this->_deferredPartialObjectExpressions) {
$this->_processDeferredPartialObjectExpressions(); $this->_processDeferredPartialObjectExpressions();
} }
if ($this->_deferredPathExpressions) { if ($this->_deferredPathExpressions) {
$this->_processDeferredPathExpressions($AST); $this->_processDeferredPathExpressions($AST);
} }
if ($this->_deferredResultVariables) { if ($this->_deferredResultVariables) {
$this->_processDeferredResultVariables(); $this->_processDeferredResultVariables();
} }
...@@ -456,7 +459,7 @@ class Parser ...@@ -456,7 +459,7 @@ class Parser
// Check if IdentificationVariable exists in queryComponents // Check if IdentificationVariable exists in queryComponents
if ( ! isset($this->_queryComponents[$identVariable])) { if ( ! isset($this->_queryComponents[$identVariable])) {
$this->semanticalError( $this->semanticalError(
"'$identVariable' is not defined.", $deferredItem['token'] "'$identVariable' is not defined.", $deferredItem['token']
); );
} }
...@@ -465,14 +468,14 @@ class Parser ...@@ -465,14 +468,14 @@ class Parser
// Check if queryComponent points to an AbstractSchemaName or a ResultVariable // Check if queryComponent points to an AbstractSchemaName or a ResultVariable
if ( ! isset($qComp['metadata'])) { if ( ! isset($qComp['metadata'])) {
$this->semanticalError( $this->semanticalError(
"'$identVariable' does not point to a Class.", $deferredItem['token'] "'$identVariable' does not point to a Class.", $deferredItem['token']
); );
} }
// Validate if identification variable nesting level is lower or equal than the current one // Validate if identification variable nesting level is lower or equal than the current one
if ($qComp['nestingLevel'] > $deferredItem['nestingLevel']) { if ($qComp['nestingLevel'] > $deferredItem['nestingLevel']) {
$this->semanticalError( $this->semanticalError(
"'$identVariable' is used outside the scope of its declaration.", $deferredItem['token'] "'$identVariable' is used outside the scope of its declaration.", $deferredItem['token']
); );
} }
} }
...@@ -486,15 +489,15 @@ class Parser ...@@ -486,15 +489,15 @@ class Parser
foreach ($expr->partialFieldSet as $field) { foreach ($expr->partialFieldSet as $field) {
if ( ! isset($class->fieldMappings[$field])) { if ( ! isset($class->fieldMappings[$field])) {
$this->semanticalError( $this->semanticalError(
"There is no mapped field named '$field' on class " . $class->name . ".", "There is no mapped field named '$field' on class " . $class->name . ".",
$deferredItem['token'] $deferredItem['token']
); );
} }
} }
if (array_intersect($class->identifier, $expr->partialFieldSet) != $class->identifier) { if (array_intersect($class->identifier, $expr->partialFieldSet) != $class->identifier) {
$this->semanticalError( $this->semanticalError(
"The partial field selection of class " . $class->name . " must contain the identifier.", "The partial field selection of class " . $class->name . " must contain the identifier.",
$deferredItem['token'] $deferredItem['token']
); );
} }
} }
...@@ -514,7 +517,7 @@ class Parser ...@@ -514,7 +517,7 @@ class Parser
// Check if ResultVariable exists in queryComponents // Check if ResultVariable exists in queryComponents
if ( ! isset($this->_queryComponents[$resultVariable])) { if ( ! isset($this->_queryComponents[$resultVariable])) {
$this->semanticalError( $this->semanticalError(
"'$resultVariable' is not defined.", $deferredItem['token'] "'$resultVariable' is not defined.", $deferredItem['token']
); );
} }
...@@ -523,14 +526,14 @@ class Parser ...@@ -523,14 +526,14 @@ class Parser
// Check if queryComponent points to an AbstractSchemaName or a ResultVariable // Check if queryComponent points to an AbstractSchemaName or a ResultVariable
if ( ! isset($qComp['resultVariable'])) { if ( ! isset($qComp['resultVariable'])) {
$this->semanticalError( $this->semanticalError(
"'$identVariable' does not point to a ResultVariable.", $deferredItem['token'] "'$identVariable' does not point to a ResultVariable.", $deferredItem['token']
); );
} }
// Validate if identification variable nesting level is lower or equal than the current one // Validate if identification variable nesting level is lower or equal than the current one
if ($qComp['nestingLevel'] > $deferredItem['nestingLevel']) { if ($qComp['nestingLevel'] > $deferredItem['nestingLevel']) {
$this->semanticalError( $this->semanticalError(
"'$resultVariable' is used outside the scope of its declaration.", $deferredItem['token'] "'$resultVariable' is used outside the scope of its declaration.", $deferredItem['token']
); );
} }
} }
...@@ -625,6 +628,7 @@ class Parser ...@@ -625,6 +628,7 @@ class Parser
), ),
null null
); );
$AST->fromClause->identificationVariableDeclarations[0]->joinVariableDeclarations[] = $joinVariableDeclaration; $AST->fromClause->identificationVariableDeclarations[0]->joinVariableDeclarations[] = $joinVariableDeclaration;
$this->_queryComponents[$aliasIdentificationVariable . '.' . $field] = $joinQueryComponent; $this->_queryComponents[$aliasIdentificationVariable . '.' . $field] = $joinQueryComponent;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment