Skip to content

Loading…

Add missing argument validators #1081

Merged
merged 24 commits into from

2 participants

@siad007

This commit add the missing arguments validators and maps error codes to severity (solves a TODO: Make configurable).

@mvriel mvriel commented on an outdated diff
...phpDocumentor/Descriptor/ProjectDescriptorBuilder.php
@@ -185,4 +185,34 @@ public function validate($descriptor)
return $errors;
}
+
+ /**
+ * Map error code to severity.
+ *
+ * @param int $code
+ *
+ * @return string
+ */
+ protected function mapCodeToSeverity($code)
+ {
+ switch ($code) {
@mvriel phpDocumentor member
mvriel added a note

is it possible to create a mapping in the ServiceProvider of a plugin (where the messages are defined)? That way people can add their own messages and define their own severities

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel
phpDocumentor member

Hmmm, I am out of time.. I will continue this review later

@mvriel mvriel commented on an outdated diff
...nstraints/Functions/AreAllArgumentsValidValidator.php
((11 lines not shown))
+
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use phpDocumentor\Descriptor\MethodDescriptor;
+use phpDocumentor\Descriptor\FunctionDescriptor;
+use phpDocumentor\Descriptor\Collection;
+use Symfony\Component\Validator\Constraint;
+use Symfony\Component\Validator\ConstraintValidator;
+use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
+
+class AreAllArgumentsValidValidator extends ConstraintValidator
+{
+ /**
+ * @see \Symfony\Component\Validator\ConstraintValidatorInterface::validate()
+ */
+ public function validate($value, Constraint $constraint)
@mvriel phpDocumentor member
mvriel added a note

The complexity and size for this method is too large; can you break it up into several methods that match individual responsibilities? I will review the functionality after this refactoring because it will also increase readability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@siad007 siad007 changed the title from Add missing argument validators to [WIP] Add missing argument validators
@siad007 siad007 changed the title from [WIP] Add missing argument validators to Add missing argument validators
@siad007

@mvriel so this should be ready for a new (or hopefully the final) review...

@mvriel
phpDocumentor member

Starting review; apparently something got merged in between that conflicts with your PR .. Can you merge develop in this branch so I can merge it after the review is complete?

@mvriel mvriel commented on an outdated diff
...phpDocumentor/Descriptor/ProjectDescriptorBuilder.php
((13 lines not shown))
+ {
+ if (is_int($code) && $this->translator->translate('VAL:ERRLVL-'.$code)) {
+ $severity = $this->translator->translate('VAL:ERRLVL-'.$code);
+ } else {
+ $severity = LogLevel::ERROR;
+ }
+
+ return $severity;
+ }
+
+ /**
+ * @param Translator $translator
+ *
+ * @return void
+ */
+ public function setTranlator(Translator $translator)
@mvriel phpDocumentor member
mvriel added a note

Small typo: should be setTranslator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel mvriel commented on an outdated diff
src/phpDocumentor/Descriptor/ServiceProvider.php
@@ -298,6 +297,7 @@ function ($container) {
$container['descriptor.filter'],
$container['validator']
);
+ $builder->setTranlator($container['translator']);
@mvriel phpDocumentor member
mvriel added a note

Small typo: should be setTranslator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel mvriel commented on an outdated diff
...traints/Classes/HasPackageWithSubpackageValidator.php
@@ -47,8 +47,9 @@ public function validate($value, Constraint $constraint)
);
}
- if ($value->getTags()->get('subpackage', new Collection())->count() > 0 && !$value->getPackage()) {
- $this->context->addViolationAt('package', $constraint->message);
+ if ($value->getTags()->get('subpackage', new Collection())->count() > 0
+ && $value->getTags()->get('package', new Collection())->count() < 1) {
@mvriel phpDocumentor member
mvriel added a note

:+1: Good change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel mvriel commented on an outdated diff
...idator/Constraints/Functions/AreAllArgumentsValid.php
((6 lines not shown))
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * Validates whether a function has a default return type in the docblock present.
+ *
+ * @Annotation
+ */
+class AreAllArgumentsValid extends Constraint
+{
@mvriel phpDocumentor member
mvriel added a note

Could it be that I am missing a message and code public property here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel mvriel commented on an outdated diff
.../Constraints/Functions/DoesArgumentNameMatchParam.php
((5 lines not shown))
+ * PHP Version 5.3
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * Validates whether a function has a default return type in the docblock present.
+ *
+ * @Annotation
+ */
+class DoesArgumentNameMatchParam extends Constraint
@mvriel phpDocumentor member
mvriel added a note

I am not sure but is this Annotation definition necessary? I get the feeling that the associated DoesArgumentNameMatchParamValidator validator class can only be invoked from the AreAllArgumentsValidValidator class; is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel mvriel commented on an outdated diff
...straints/Functions/DoesArgumentTypehintMatchParam.php
((8 lines not shown))
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * Checks the typehint of the argument versus the @param tag.
+ *
+ * If the argument has no typehint we do not check anything. When multiple
+ * type are given then the typehint needs to be one of them.
+ *
+ * @Annotation
+ */
+class DoesArgumentTypehintMatchParam extends Constraint
@mvriel phpDocumentor member
mvriel added a note

I am not sure but is this Annotation definition necessary? I get the feeling that the associated DoesArgumentTypehintMatchParamValidator validator class can only be invoked from the AreAllArgumentsValidValidator class; is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel mvriel commented on an outdated diff
.../Validator/Constraints/Functions/DoesParamsExists.php
((5 lines not shown))
+ * PHP Version 5.3
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * Validates whether a function has a default return type in the docblock present.
+ *
+ * @Annotation
+ */
+class DoesParamsExists extends Constraint
@mvriel phpDocumentor member
mvriel added a note

I am not sure but is this Annotation definition necessary? I get the feeling that the associated DoesParamsExistsValidator validator class can only be invoked from the AreAllArgumentsValidValidator class; is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel mvriel commented on the diff
...idator/Constraints/Functions/IsArgumentInDocBlock.php
@@ -22,6 +22,8 @@ class IsArgumentInDocBlock extends Constraint
/** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
public $message = 'PPC:ERR-50015';
@mvriel phpDocumentor member
mvriel added a note

I am not sure but is this Annotation definition necessary? I get the feeling that the associated IsArgumentInDocBlockValidator validator class can only be invoked from the AreAllArgumentsValidValidator class; is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel
phpDocumentor member

@siad007 I noticed that several validator are subvalidators of one; because they rather looked like normal validators I was slightly confused. I got the feeling that they do not need to be complete validators but can also be a simpler class that contains the business rule that you need in the original validator or am I wrong?

@mvriel mvriel commented on the diff
...nstraints/Functions/AreAllArgumentsValidValidator.php
((68 lines not shown))
+
+ $this->validationValue->fqsen = $value->getFullyQualifiedStructuralElementName();
+ $this->validationValue->arguments = $value->getArguments();
+ $this->validationValue->parameters = $value->getParam();
+ $this->validationValue->name = $value->getName();
+ }
+
+ /**
+ * @return null
+ */
+ protected function processArgumentValidation()
+ {
+ $arguments = $this->validationValue->arguments->getAll();
+
+ foreach (array_values($arguments) as $key => $argument) {
+ $this->validationValue->key = $key;
@mvriel phpDocumentor member
mvriel added a note

I get the feeling here that you intend to pass these values to the methods below; but in this way the last argument's state is always preserved in this validationValueObject.

Perhaps a more effective approach is to pass the required values as arguments to the check methods below instead of a property.

This practice of injecting dependencies is a good way to deal with all kinds of situations because using global objects (this validation value object is a sort of global object in the class) causes hidden dependencies and making it harder to read the code. While if you pass arguments and dependencies using parameters then it is clear for the reader what that class or method depends on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel
phpDocumentor member

Sorry about the comments; if it troublesome for you, let me know and I can merge the PR and do some minor changes to make it fit.

@siad007

@mvriel i agree not to be lucky with the use of an global object (validationValueObject) but we wanted to make the violation messages "translateable" wich is done in the validators by their messages, thats why i make them as subvalidators. Unfortunately there is only one parameter that i can give the validate method to validate against -> Symfony\Component\ValidatorConstraintValidatorInterface::validate($value, Constraint $constraint)

What do you suggest?

p.s. i also merged the develop branch in

@mvriel
phpDocumentor member

@siad007 if you pass the translator as constructor dependency for each validator int he service provider; is it then possible to have them as separate validators instead of them depending on eachother?

@siad007 siad007 commented on the diff
...phpDocumentor/Descriptor/ProjectDescriptorBuilder.php
@@ -175,7 +179,7 @@ public function validate($descriptor)
foreach ($violations as $violation) {
$errors->add(
new Error(
- LogLevel::ERROR, // TODO: Make configurable
+ $this->mapCodeToSeverity($violation->getCode()),
$violation->getMessageTemplate(),
@siad007
siad007 added a note

@mvriel i think this is the point of view. here is the error object filled with one message template which is taken by one validator. With this in mind there is the initialization of the validators by adding a constraint. but we want to have is a logic like if validator a is true validator b is obsolete for example. we then need a kind of buildplan like that i tried to implement with an "validator" to roole them all with the property not to have an violation. sure i can make them "stand alone" validators but we just need the logic to avoid calling a validator if another fails. thats why i implemented it that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvriel
phpDocumentor member

Hi @siad007, I wanted to merge this feature but discovered that a merge conflict has occurred somewhere along the way. Can you merge develop in again for me? Thank you

siad007 added some commits
@siad007 siad007 rewrite validators to suite the new way of doing ca9c5b7
@siad007 siad007 rewrite validators to suite the new way of doing 3d7ff67
@siad007 siad007 clean up f57c46b
@siad007 siad007 clean up f56af8a
@siad007 siad007 Fixed name of validator call 125c6f9
@siad007 siad007 Split too "long method" to make things clearer. 6f99d89
@siad007 siad007 added violation codes and some minor bug fixes 62387e1
@siad007 siad007 add code f38498c
@siad007 siad007 added severity for validation code mapping a32557d
@siad007 siad007 made violation severity configurable 8bba057
@siad007 siad007 added translation to builder ca95094
@siad007 siad007 bug fixes de14061
@siad007 siad007 some more splitting 011578f
@siad007 siad007 introduce ValidatorValueObject d4d9d2d
@siad007 siad007 removed annotations ced73d5
@siad007 siad007 fixed typo e836631
@siad007 siad007 removed to much insertions for another commit 2756364
@siad007 siad007 removed unwanted changes b772194
@siad007 siad007 resolved merge conflict
b32a0cd
@siad007 siad007 resolved merge conflict
8cc8434
@siad007 siad007 resolved merge conflict
6e28654
@siad007 siad007 fixed test
d734af0
@siad007 siad007 fixed test
5eaa19c
@siad007 siad007 fixed test
24b5a5e
@siad007

@mvriel just resolved the merge conflicts and repaired some validator tests. please check carefully - i did not double check the result for this huge merge but the test suite passes.

@mvriel
phpDocumentor member

I did a local checkout and it seems to work fine except for a few fatal errors that arose. Because I want to do a release I am not going to merge this now but wait until after the release so that I have time to write unit tests for these changes

@mvriel mvriel merged commit 24b5a5e into phpDocumentor:develop

3 checks passed

Details ci/scrutinizer Scrutinizer: 26 new issues, 28 updated code elements — Tests: passed
Details continuous-integration/travis-ci The Travis CI build passed
Details continuous-integration/wercker Build finished
@mvriel
phpDocumentor member

Hi @siad007, it took some time but I merged your PR. Thanks again for submitting it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 2, 2014
  1. @siad007
  2. @siad007
  3. @siad007

    clean up

    siad007 committed
  4. @siad007

    clean up

    siad007 committed
  5. @siad007

    Fixed name of validator call

    siad007 committed
  6. @siad007
  7. @siad007
  8. @siad007

    add code

    siad007 committed
  9. @siad007
  10. @siad007
  11. @siad007

    added translation to builder

    siad007 committed
  12. @siad007

    bug fixes

    siad007 committed
  13. @siad007

    some more splitting

    siad007 committed
  14. @siad007

    introduce ValidatorValueObject

    siad007 committed
  15. @siad007

    removed annotations

    siad007 committed
  16. @siad007

    fixed typo

    siad007 committed
  17. @siad007
  18. @siad007

    removed unwanted changes

    siad007 committed
  19. @siad007

    resolved merge conflict

    siad007 committed
  20. @siad007

    resolved merge conflict

    siad007 committed
  21. @siad007

    resolved merge conflict

    siad007 committed
  22. @siad007

    fixed test

    siad007 committed
  23. @siad007

    fixed test

    siad007 committed
  24. @siad007

    fixed test

    siad007 committed
This page is out of date. Refresh to see the latest.
Showing with 635 additions and 46 deletions.
  1. +33 −1 src/phpDocumentor/Descriptor/ProjectDescriptorBuilder.php
  2. +8 −8 src/phpDocumentor/Descriptor/ServiceProvider.php
  3. +2 −2 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasPackageWithSubpackage.php
  4. +1 −1 ...mentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasPackageWithSubpackageValidator.php
  5. +2 −2 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSinglePackage.php
  6. +1 −1 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSinglePackageValidator.php
  7. +2 −2 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSingleSubpackage.php
  8. +1 −1 ...pDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSingleSubpackageValidator.php
  9. +29 −0 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/AreAllArgumentsValid.php
  10. +152 −0 ...cumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/AreAllArgumentsValidValidator.php
  11. +34 −0 ...pDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/DoesArgumentNameMatchParam.php
  12. +61 −0 ...or/Plugin/Core/Descriptor/Validator/Constraints/Functions/DoesArgumentNameMatchParamValidator.php
  13. +37 −0 ...umentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/DoesArgumentTypehintMatchParam.php
  14. +58 −0 ...lugin/Core/Descriptor/Validator/Constraints/Functions/DoesArgumentTypehintMatchParamValidator.php
  15. +34 −0 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/DoesParamsExists.php
  16. +60 −0 ...hpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/DoesParamsExistsValidator.php
  17. +2 −2 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/IsArgumentInDocBlock.php
  18. +12 −14 ...cumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/IsArgumentInDocBlockValidator.php
  19. +2 −2 ...pDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/IsParamTypeNotAnIdeDefault.php
  20. +5 −1 ...or/Plugin/Core/Descriptor/Validator/Constraints/Functions/IsParamTypeNotAnIdeDefaultValidator.php
  21. +2 −2 ...Documentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/IsReturnTypeNotAnIdeDefault.php
  22. +4 −1 ...r/Plugin/Core/Descriptor/Validator/Constraints/Functions/IsReturnTypeNotAnIdeDefaultValidator.php
  23. +2 −2 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Property/HasSummary.php
  24. +1 −1 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Property/HasSummaryValidator.php
  25. +47 −0 src/phpDocumentor/Plugin/Core/Descriptor/Validator/ValidationValueObject.php
  26. +19 −0 src/phpDocumentor/Plugin/Core/Messages/de.php
  27. +19 −0 src/phpDocumentor/Plugin/Core/Messages/en.php
  28. +3 −1 ...or/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasPackageWithSubpackageValidatorTest.php
  29. +1 −1 ...Documentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSinglePackageValidatorTest.php
  30. +1 −1 ...umentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSingleSubpackageValidatorTest.php
View
34 src/phpDocumentor/Descriptor/ProjectDescriptorBuilder.php
@@ -17,6 +17,7 @@
use phpDocumentor\Descriptor\Filter\Filterable;
use phpDocumentor\Descriptor\ProjectDescriptor\Settings;
use phpDocumentor\Descriptor\Validator\Error;
+use phpDocumentor\Translator\Translator;
use Psr\Log\LogLevel;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\Validator;
@@ -41,6 +42,9 @@ class ProjectDescriptorBuilder
/** @var ProjectDescriptor $project */
protected $project;
+ /** @var Translator $translator */
+ protected $translator;
+
public function __construct(AssemblerFactory $assemblerFactory, Filter $filterManager, Validator $validator)
{
$this->assemblerFactory = $assemblerFactory;
@@ -187,7 +191,7 @@ public function validate($descriptor)
foreach ($violations as $violation) {
$errors->add(
new Error(
- LogLevel::ERROR, // TODO: Make configurable
+ $this->mapCodeToSeverity($violation->getCode()),
$violation->getMessageTemplate(),
@siad007
siad007 added a note

@mvriel i think this is the point of view. here is the error object filled with one message template which is taken by one validator. With this in mind there is the initialization of the validators by adding a constraint. but we want to have is a logic like if validator a is true validator b is obsolete for example. we then need a kind of buildplan like that i tried to implement with an "validator" to roole them all with the property not to have an violation. sure i can make them "stand alone" validators but we just need the logic to avoid calling a validator if another fails. thats why i implemented it that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
$descriptor->getLine(),
$violation->getMessageParameters() + array($descriptor->getFullyQualifiedStructuralElementName())
@@ -245,5 +249,33 @@ protected function filterAndValidateDescriptor($descriptor)
$descriptor->setErrors($this->validate($descriptor));
return $descriptor;
+ }
+
+ /**
+ * Map error code to severity.
+ *
+ * @param int $code
+ *
+ * @return string
+ */
+ protected function mapCodeToSeverity($code)
+ {
+ if (is_int($code) && $this->translator->translate('VAL:ERRLVL-'.$code)) {
+ $severity = $this->translator->translate('VAL:ERRLVL-'.$code);
+ } else {
+ $severity = LogLevel::ERROR;
+ }
+
+ return $severity;
+ }
+
+ /**
+ * @param Translator $translator
+ *
+ * @return void
+ */
+ public function setTranslator(Translator $translator)
+ {
+ $this->translator = $translator;
}
}
View
16 src/phpDocumentor/Descriptor/ServiceProvider.php
@@ -4,7 +4,7 @@
*
* PHP Version 5.3
*
- * @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com)
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
@@ -190,11 +190,10 @@ public function attachFiltersToManager(Filter $filterManager, Application $app)
);
foreach ($filtersOnAllDescriptors as $filter) {
- $filterManager->attach('phpDocumentor\Descriptor\ClassDescriptor', $filter);
- $filterManager->attach('phpDocumentor\Descriptor\InterfaceDescriptor', $filter);
- $filterManager->attach('phpDocumentor\Descriptor\TraitDescriptor', $filter);
$filterManager->attach('phpDocumentor\Descriptor\ConstantDescriptor', $filter);
$filterManager->attach('phpDocumentor\Descriptor\FunctionDescriptor', $filter);
+ $filterManager->attach('phpDocumentor\Descriptor\InterfaceDescriptor', $filter);
+ $filterManager->attach('phpDocumentor\Descriptor\TraitDescriptor', $filter);
$filterManager->attach('phpDocumentor\Descriptor\PropertyDescriptor', $filter);
$filterManager->attach('phpDocumentor\Descriptor\MethodDescriptor', $filter);
}
@@ -216,7 +215,8 @@ public function attachValidators(Validator $validator)
{
/** @var ClassMetadata $fileMetadata */
$fileMetadata = $validator->getMetadataFor('phpDocumentor\Descriptor\FileDescriptor');
- $validator->getMetadataFor('phpDocumentor\Descriptor\ConstantDescriptor');
+ /** @var ClassMetadata $constantMetadata */
+ $constantMetadata = $validator->getMetadataFor('phpDocumentor\Descriptor\ConstantDescriptor');
/** @var ClassMetadata $functionMetadata */
$functionMetadata = $validator->getMetadataFor('phpDocumentor\Descriptor\FunctionDescriptor');
/** @var ClassMetadata $classMetadata */
@@ -243,9 +243,8 @@ public function attachValidators(Validator $validator)
$functionMetadata->addConstraint(new phpDocAssert\Functions\IsParamTypeNotAnIdeDefault());
$methodMetadata->addConstraint(new phpDocAssert\Functions\IsParamTypeNotAnIdeDefault());
-
- $functionMetadata->addConstraint(new phpDocAssert\Functions\IsArgumentInDocBlock());
- $methodMetadata->addConstraint(new phpDocAssert\Functions\IsArgumentInDocBlock());
+ $functionMetadata->addConstraint(new phpDocAssert\Functions\AreAllArgumentsValid());
+ $methodMetadata->addConstraint(new phpDocAssert\Functions\AreAllArgumentsValid());
$classMetadata->addConstraint(new phpDocAssert\Classes\HasSinglePackage());
$interfaceMetadata->addConstraint(new phpDocAssert\Classes\HasSinglePackage());
@@ -324,6 +323,7 @@ function ($container) {
$container['descriptor.filter'],
$container['validator']
);
+ $builder->setTranslator($container['translator']);
return $builder;
}
View
4 ...umentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasPackageWithSubpackage.php
@@ -14,14 +14,14 @@
/**
* Validates whether a file, class, interface or trait always has a package if there is a subpackage present.
- *
- * @Annotation
*/
class HasPackageWithSubpackage extends Constraint
{
/** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
public $message = 'PPC:ERR-50004';
+ public $code = 50004;
+
/**
* Returns that the constraint can be put onto classes.
*
View
2 ...lugin/Core/Descriptor/Validator/Constraints/Classes/HasPackageWithSubpackageValidator.php
@@ -49,7 +49,7 @@ public function validate($value, Constraint $constraint)
if ($value->getTags()->get('subpackage', new Collection())->count() > 0
&& $value->getTags()->get('package', new Collection())->count() < 1) {
- $this->context->addViolationAt('package', $constraint->message);
+ $this->context->addViolationAt('package', $constraint->message, array(), null, null, $constraint->code);
}
}
}
View
4 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSinglePackage.php
@@ -14,14 +14,14 @@
/**
* Validates whether a file, class, interface or trait has not more than ! package tags.
- *
- * @Annotation
*/
class HasSinglePackage extends Constraint
{
/** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
public $message = 'PPC:ERR-50001';
+ public $code = 50001;
+
/**
* Returns that the constraint can be put onto classes.
*
View
2 ...mentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSinglePackageValidator.php
@@ -47,7 +47,7 @@ public function validate($value, Constraint $constraint)
}
if ($value->getTags()->get('package', new Collection())->count() > 1) {
- $this->context->addViolationAt('package', $constraint->message);
+ $this->context->addViolationAt('package', $constraint->message, array(), null, null, $constraint->code);
}
}
}
View
4 ...hpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSingleSubpackage.php
@@ -14,14 +14,14 @@
/**
* Validates whether a file, class, interface or trait has not more than 1 subpackage tags.
- *
- * @Annotation
*/
class HasSingleSubpackage extends Constraint
{
/** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
public $message = 'PPC:ERR-50002';
+ public $code = 50002;
+
/**
* Returns that the constraint can be put onto classes.
*
View
2 ...tor/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSingleSubpackageValidator.php
@@ -47,7 +47,7 @@ public function validate($value, Constraint $constraint)
}
if ($value->getTags()->get('subpackage', new Collection())->count() > 1) {
- $this->context->addViolationAt('package', $constraint->message);
+ $this->context->addViolationAt('package', $constraint->message, array(), null, null, $constraint->code);
}
}
}
View
29 ...ocumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/AreAllArgumentsValid.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * phpDocumentor
+ *
+ * PHP Version 5.3
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * Validates whether a function has a default return type in the docblock present.
+ */
+class AreAllArgumentsValid extends Constraint
+{
+ /**
+ * Returns that the constraint can be put onto classes.
+ *
+ * @return string
+ */
+ public function getTargets()
+ {
+ return array(self::CLASS_CONSTRAINT);
+ }
+}
View
152 .../Plugin/Core/Descriptor/Validator/Constraints/Functions/AreAllArgumentsValidValidator.php
@@ -0,0 +1,152 @@
+<?php
+/**
+ * phpDocumentor
+ *
+ * PHP Version 5.3
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use phpDocumentor\Descriptor\MethodDescriptor;
+use phpDocumentor\Descriptor\FunctionDescriptor;
+use phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions\DoesArgumentNameMatchParam;
+use phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions\DoesArgumentNameMatchParamValidator;
+use phpDocumentor\Plugin\Core\Descriptor\Validator\ValidationValueObject;
+use Symfony\Component\Validator\Constraint;
+use Symfony\Component\Validator\ConstraintValidator;
+use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
+
+/**
+ *
+ */
+class AreAllArgumentsValidValidator extends ConstraintValidator
+{
+ /** @var Constraint $constraint */
+ protected $constraint;
+
+ /**
+ * Value to validate agains.
+ *
+ * @var Collection
+ */
+ protected $validationValue = null;
+
+ /**
+ * @see \Symfony\Component\Validator\ConstraintValidatorInterface::validate()
+ *
+ * @throws ConstraintDefinitionException
+ */
+ public function validate($value, Constraint $constraint)
+ {
+ if (! $value instanceof MethodDescriptor
+ && ! $value instanceof FunctionDescriptor
+ ) {
+ throw new ConstraintDefinitionException(
+ 'The Functions\AreAllArgumentsValid validator may only be used on function or method objects'
+ );
+ }
+
+ $this->constraint = $constraint;
+
+ $this->initValueObject($value);
+
+ $violation = $this->processArgumentValidation();
+ if ($violation) {
+ return $violation;
+ }
+
+ $this->checkParamsExists();
+ }
+
+ protected function initValueObject($value)
+ {
+ $this->validationValue = new ValidationValueObject();
+
+ $this->validationValue->fqsen = $value->getFullyQualifiedStructuralElementName();
+ $this->validationValue->arguments = $value->getArguments();
+ $this->validationValue->parameters = $value->getParam();
+ $this->validationValue->name = $value->getName();
+ }
+
+ /**
+ * @return null
+ */
+ protected function processArgumentValidation()
+ {
+ $arguments = $this->validationValue->arguments->getAll();
+
+ foreach (array_values($arguments) as $key => $argument) {
+ $this->validationValue->key = $key;
@mvriel phpDocumentor member
mvriel added a note

I get the feeling here that you intend to pass these values to the methods below; but in this way the last argument's state is always preserved in this validationValueObject.

Perhaps a more effective approach is to pass the required values as arguments to the check methods below instead of a property.

This practice of injecting dependencies is a good way to deal with all kinds of situations because using global objects (this validation value object is a sort of global object in the class) causes hidden dependencies and making it harder to read the code. While if you pass arguments and dependencies using parameters then it is clear for the reader what that class or method depends on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $this->validationValue->argument = $argument;
+ $this->validationValue->index = $key;
+ $this->validationValue->parameter = $this->validationValue->parameters[$key];
+
+ if ($this->checkArgumentInDocBlock()) {
+ continue;
+ }
+
+ $violation = $this->checkArgumentNameMatchParam();
+ if ($violation) {
+ return $violation;
+ }
+
+ $violation = $this->checkArgumentTypehintMatchParam();
+ if ($violation) {
+ return $violation;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Check if argument is inside docblock.
+ */
+ protected function checkArgumentInDocBlock()
+ {
+ $validator = new IsArgumentInDocBlockValidator();
+ $validator->initialize($this->context);
+
+ return $validator->validate($this->validationValue, new IsArgumentInDocBlock);
+ }
+
+ /**
+ * Check if argument matches parameter.
+ */
+ protected function checkArgumentNameMatchParam()
+ {
+ $validator = new DoesArgumentNameMatchParamValidator;
+ $validator->initialize($this->context);
+
+ return $validator->validate($this->validationValue, new DoesArgumentNameMatchParam);
+ }
+
+ /**
+ * Check if argument typehint matches parameter.
+ */
+ protected function checkArgumentTypehintMatchParam()
+ {
+ $validator = new DoesArgumentTypehintMatchParamValidator;
+ $validator->initialize($this->context);
+
+ return $validator->validate($this->validationValue, new DoesArgumentTypehintMatchParam);
+ }
+
+ /**
+ * Check if parameter exists for argument.
+ *
+ * @param Collection $params
+ * @param Collection $arguments
+ */
+ protected function checkParamsExists()
+ {
+ $validator = new DoesParamsExistsValidator();
+ $validator->initialize($this->context);
+
+ return $validator->validate($this->validationValue, new DoesParamsExists);
+ }
+}
View
34 ...tor/Plugin/Core/Descriptor/Validator/Constraints/Functions/DoesArgumentNameMatchParam.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * phpDocumentor
+ *
+ * PHP Version 5.3
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * Validates whether a function has a default return type in the docblock present.
+ */
+class DoesArgumentNameMatchParam extends Constraint
+{
+ /** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
+ public $message = 'PPC:ERR-50014';
+
+ public $code = 50014;
+
+ /**
+ * Returns that the constraint can be put onto classes.
+ *
+ * @return string
+ */
+ public function getTargets()
+ {
+ return array(self::CLASS_CONSTRAINT);
+ }
+}
View
61 ...n/Core/Descriptor/Validator/Constraints/Functions/DoesArgumentNameMatchParamValidator.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * phpDocumentor
+ *
+ * PHP Version 5.3
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use phpDocumentor\Descriptor\MethodDescriptor;
+use phpDocumentor\Descriptor\FunctionDescriptor;
+use phpDocumentor\Descriptor\Tag\ParamDescriptor;
+use Symfony\Component\Validator\Constraint;
+use Symfony\Component\Validator\ConstraintValidator;
+use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
+use phpDocumentor\Plugin\Core\Descriptor\Validator\ValidationValueObject;
+
+class DoesArgumentNameMatchParamValidator extends ConstraintValidator
+{
+ /**
+ * @see \Symfony\Component\Validator\ConstraintValidatorInterface::validate()
+ */
+ public function validate($value, Constraint $constraint)
+ {
+ if (!$value instanceof ValidationValueObject) {
+ throw new ConstraintDefinitionException(
+ 'The Functions\DoesArgumentNameMatchParam subvalidator may only be used on '
+ . ' an ValidationValueObject containing a parameter key, a fqsen and an argument object'
+ );
+ }
+
+ if (empty($value->parameter) || empty($value->argument)) {
+ return null;
+ }
+
+ $parameterName = $value->parameter->getVariableName();
+ $argumentName = $value->argument->getName();
+
+ if ($parameterName == $argumentName) {
+ return null;
+ }
+
+ if ($parameterName == '') {
+ $value->parameter->setVariableName($argumentName);
+ return null;
+ }
+
+ $violation = $this->context->addViolationAt(
+ 'argument',
+ $constraint->message,
+ array($argumentName, $parameterName, $value->fqsen),
+ null,
+ null,
+ $constraint->code
+ );
+ }
+}
View
37 ...Plugin/Core/Descriptor/Validator/Constraints/Functions/DoesArgumentTypehintMatchParam.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * phpDocumentor
+ *
+ * PHP Version 5.3
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * Checks the typehint of the argument versus the @param tag.
+ *
+ * If the argument has no typehint we do not check anything. When multiple
+ * type are given then the typehint needs to be one of them.
+ */
+class DoesArgumentTypehintMatchParam extends Constraint
+{
+ /** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
+ public $message = 'PPC:ERR-50016';
+
+ public $code = 50016;
+
+ /**
+ * Returns that the constraint can be put onto classes.
+ *
+ * @return string
+ */
+ public function getTargets()
+ {
+ return array(self::CLASS_CONSTRAINT);
+ }
+}
View
58 ...re/Descriptor/Validator/Constraints/Functions/DoesArgumentTypehintMatchParamValidator.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * phpDocumentor
+ *
+ * PHP Version 5.3
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use phpDocumentor\Descriptor\MethodDescriptor;
+use phpDocumentor\Descriptor\FunctionDescriptor;
+use phpDocumentor\Descriptor\Tag\ParamDescriptor;
+use Symfony\Component\Validator\Constraint;
+use Symfony\Component\Validator\ConstraintValidator;
+use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
+use phpDocumentor\Descriptor\ArgumentDescriptor;
+use phpDocumentor\Plugin\Core\Descriptor\Validator\ValidationValueObject;
+
+class DoesArgumentTypehintMatchParamValidator extends ConstraintValidator
+{
+ /**
+ * @see \Symfony\Component\Validator\ConstraintValidatorInterface::validate()
+ */
+ public function validate($value, Constraint $constraint)
+ {
+ if (!$value instanceof ValidationValueObject) {
+ throw new ConstraintDefinitionException(
+ 'The Functions\DoesArgumentTypehintMatchParam subvalidator may only be used on '
+ . ' an array containing a parameter key, a fqsen and an argument object'
+ );
+ }
+
+ $argument = $value->argument;
+ $parameter = $value->parameter;
+
+ if ($argument instanceof ArgumentDescriptor && $parameter instanceof ParamDescriptor ) {
+
+ if (count($argument->getTypes()) === 0 || in_array(current($argument->getTypes()), $parameter->getTypes())) {
+ return null;
+ } elseif (current($argument->getTypes()) === 'array' && substr(current($parameter->getTypes()), -2) == '[]') {
+ return null;
+ }
+
+ $this->context->addViolationAt(
+ 'argument',
+ $constraint->message,
+ array($argument->getName(), $value->fqsen),
+ null,
+ null,
+ $constraint->code
+ );
+ }
+ }
+}
View
34 ...phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/DoesParamsExists.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * phpDocumentor
+ *
+ * PHP Version 5.3
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use Symfony\Component\Validator\Constraint;
+
+/**
+ * Validates whether a function has a default return type in the docblock present.
+ */
+class DoesParamsExists extends Constraint
+{
+ /** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
+ public $message = 'PPC:ERR-50013';
+
+ public $code = 50013;
+
+ /**
+ * Returns that the constraint can be put onto classes.
+ *
+ * @return string
+ */
+ public function getTargets()
+ {
+ return array(self::CLASS_CONSTRAINT);
+ }
+}
View
60 ...ntor/Plugin/Core/Descriptor/Validator/Constraints/Functions/DoesParamsExistsValidator.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * phpDocumentor
+ *
+ * PHP Version 5.3
+ *
+ * @copyright 2010-2013 Mike van Riel / Naenius (http://www.naenius.com)
+ * @license http://www.opensource.org/licenses/mit-license.php MIT
+ * @link http://phpdoc.org
+ */
+
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator\Constraints\Functions;
+
+use phpDocumentor\Descriptor\MethodDescriptor;
+use phpDocumentor\Descriptor\FunctionDescriptor;
+use phpDocumentor\Descriptor\Tag\ParamDescriptor;
+use Symfony\Component\Validator\Constraint;
+use Symfony\Component\Validator\ConstraintValidator;
+use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
+use phpDocumentor\Plugin\Core\Descriptor\Validator\ValidationValueObject;
+
+class DoesParamsExistsValidator extends ConstraintValidator
+{
+ /**
+ * @see \Symfony\Component\Validator\ConstraintValidatorInterface::validate()
+ */
+ public function validate($value, Constraint $constraint)
+ {
+ if (!$value instanceof ValidationValueObject) {
+ throw new ConstraintDefinitionException(
+ 'The Functions\DoesParamsExistsValidator subvalidator may only be used on '
+ . ' a ValidationValueObject containing a parameter key, a fqsen and an argument object'
+ );
+ }
+
+ $arguments = $value->arguments;
+ $parameters = $value->parameters;
+
+ if (count($arguments) > 0) {
+ foreach($parameters as $param) {
+ $paramVarName = $param->getVariableName();
+
+ if (empty($paramVarName) || $arguments->offsetExists($paramVarName) ) {
+ continue;
+ }
+
+ $this->context->addViolationAt(
+ 'argument',
+ $constraint->message,
+ array($paramVarName, $value->fqsen),
+ null,
+ null,
+ $constraint->code
+ );
+ }
+ }
+
+ return null;
+ }
+}
View
4 ...ocumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/IsArgumentInDocBlock.php
@@ -14,14 +14,14 @@
/**
* Validates whether a function has a missing argument in the docblock.
- *
- * @Annotation
*/
class IsArgumentInDocBlock extends Constraint
{
/** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
public $message = 'PPC:ERR-50015';
@mvriel phpDocumentor member
mvriel added a note

I am not sure but is this Annotation definition necessary? I get the feeling that the associated IsArgumentInDocBlockValidator validator class can only be invoked from the AreAllArgumentsValidValidator class; is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ public $code = 50015;
+
/**
* Returns that the constraint can be put onto classes.
*
View
26 .../Plugin/Core/Descriptor/Validator/Constraints/Functions/IsArgumentInDocBlockValidator.php
@@ -15,10 +15,10 @@
use phpDocumentor\Descriptor\Collection;
use phpDocumentor\Descriptor\MethodDescriptor;
use phpDocumentor\Descriptor\FunctionDescriptor;
-use phpDocumentor\Descriptor\Tag\ParamDescriptor;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
+use phpDocumentor\Plugin\Core\Descriptor\Validator\ValidationValueObject;
/**
* Validates if a Method or Function's arguments all have an accompanying param tag in the DocBlock.
@@ -30,25 +30,23 @@ class IsArgumentInDocBlockValidator extends ConstraintValidator
*/
public function validate($value, Constraint $constraint)
{
- if (! $value instanceof MethodDescriptor && ! $value instanceof FunctionDescriptor) {
- throw new ConstraintDefinitionException(
- 'The Functions\IsArgumentInDocBlock validator may only be used on function or method objects'
- );
- }
-
- /** @var Collection|ArgumentDescriptor[] $arguments */
- $arguments = $value->getArguments();
- $parameters = $value->getTags()->get('param');
+ if ($value instanceof ValidationValueObject && count($value->argument) > 0) {
+ $argument = $value->argument;
+ /* @var $params \phpDocumentor\Descriptor\Collection */
+ $params = $value->parameters;
+ $index = $value->index;
- foreach ($arguments as $argument) {
- if ($this->existsParamTagWithArgument($parameters, $argument)) {
- continue;
+ if ($params->offsetExists($index)) {
+ return null;
}
$this->context->addViolationAt(
'argument',
$constraint->message,
- array($argument->getName(), $value->getFullyQualifiedStructuralElementName())
+ array($argument->getName(), $value->name),
+ null,
+ null,
+ $constraint->code
);
}
}
View
4 ...tor/Plugin/Core/Descriptor/Validator/Constraints/Functions/IsParamTypeNotAnIdeDefault.php
@@ -14,14 +14,14 @@
/**
* Validates whether a function has a default param type in the docblock present.
- *
- * @Annotation
*/
class IsParamTypeNotAnIdeDefault extends Constraint
{
/** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
public $message = 'PPC:ERR-50018';
+ public $code = 50018;
+
/**
* Returns that the constraint can be put onto classes.
*
View
6 ...n/Core/Descriptor/Validator/Constraints/Functions/IsParamTypeNotAnIdeDefaultValidator.php
@@ -41,6 +41,7 @@ public function validate($value, Constraint $constraint)
}
$params = $value->getParam();
+
foreach ($params as $param) {
if (! $param instanceof ParamDescriptor) {
continue;
@@ -56,7 +57,10 @@ public function validate($value, Constraint $constraint)
$this->context->addViolationAt(
'params',
$constraint->message,
- array($param->getVariableName(), $value->getFullyQualifiedStructuralElementName())
+ array($param->getVariableName(), $value->getFullyQualifiedStructuralElementName()),
+ null,
+ null,
+ $constraint->code
);
}
}
View
4 ...or/Plugin/Core/Descriptor/Validator/Constraints/Functions/IsReturnTypeNotAnIdeDefault.php
@@ -14,14 +14,14 @@
/**
* Validates whether a function has a default return type in the docblock present.
- *
- * @Annotation
*/
class IsReturnTypeNotAnIdeDefault extends Constraint
{
/** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
public $message = 'PPC:ERR-50017';
+ public $code = 50017;
+
/**
* Returns that the constraint can be put onto classes.
*
View
5 .../Core/Descriptor/Validator/Constraints/Functions/IsReturnTypeNotAnIdeDefaultValidator.php
@@ -40,7 +40,10 @@ public function validate($value, Constraint $constraint)
$this->context->addViolationAt(
'response',
$constraint->message,
- array($return->getName(), $value->getFullyQualifiedStructuralElementName())
+ array($return->getName(), $value->getFullyQualifiedStructuralElementName()),
+ null,
+ null,
+ $constraint->code
);
}
}
View
4 src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Property/HasSummary.php
@@ -14,14 +14,14 @@
/**
* Detects whether a property has a summary, or an `@var` tag with a description.
- *
- * @Annotation
*/
class HasSummary extends Constraint
{
/** @var string message phpDocumentor uses codes that are defined in a messages.[lang].php file in the a plugin. */
public $message = 'PPC:ERR-50007';
+ public $code = 50007;
+
/**
* Returns that the constraint can be put onto classes.
*
View
2 ...pDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Property/HasSummaryValidator.php
@@ -38,7 +38,7 @@ public function validate($value, Constraint $constraint)
$var = $value->getVar();
if (! $value->getSummary() && ($var->count() == 0 || ! current($var->getAll())->getDescription())) {
- $this->context->addViolationAt('summary', $constraint->message);
+ $this->context->addViolationAt('summary', $constraint->message, array(), null, null, $constraint->code);
}
}
}
View
47 src/phpDocumentor/Plugin/Core/Descriptor/Validator/ValidationValueObject.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace phpDocumentor\Plugin\Core\Descriptor\Validator;
+
+/**
+ *
+ * @property \phpDocumentor\Descriptor\ArgumentDescriptor $argument
+ * @property \phpDocumentor\Descriptor\Tag\ParamDescriptor $parameter
+ * @property \phpDocumentor\Descriptor\Collection $parameters
+ * @property string $fqsen
+ * @property string $name
+ * @property string $index
+ * @property string $key
+ */
+class ValidationValueObject extends \ArrayObject
+{
+ protected $data = array(
+ 'arguments' => '',
+ 'argument' => '',
+ 'parameter' => '',
+ 'parameters' => '',
+ 'fqsen' => '',
+ 'name' => '',
+ 'index' => '',
+ 'key' => '',
+ );
+
+ public function __get($name)
+ {
+ if (!isset($this->data[$name])) {
+ throw new \BadMethodCallException("Property {$name} not supported.");
+ }
+
+ return $this->data[$name];
+ }
+
+ public function __set($name, $value)
+ {
+ if (!isset($this->data[$name])) {
+ throw new \BadMethodCallException("Property {$name} not supported.");
+ }
+
+ if (!empty($value)) {
+ $this->data[$name] = $value;
+ }
+ }
+}
View
19 src/phpDocumentor/Plugin/Core/Messages/de.php
@@ -31,4 +31,23 @@
'PPC:ERR-50018' => 'Der Typ für das param Tag %s in %s ist entweder "type" oder "unknown"; ist das nicht ein '
. 'IDE default?',
'PPC:ERR-50020' => 'Benötigtes Tag "%s" wurde nicht in %s gefunden',
+
+ 'VAL:ERRLVL-50000' => 'error',
+ 'VAL:ERRLVL-50001' => 'error',
+ 'VAL:ERRLVL-50002' => 'error',
+ 'VAL:ERRLVL-50004' => 'warning',
+ 'VAL:ERRLVL-50005' => 'error',
+ 'VAL:ERRLVL-50006' => 'critical',
+ 'VAL:ERRLVL-50007' => 'error',
+ 'VAL:ERRLVL-50008' => 'error',
+ 'VAL:ERRLVL-50009' => 'error',
+ 'VAL:ERRLVL-50010' => 'error',
+ 'VAL:ERRLVL-50011' => 'error',
+ 'VAL:ERRLVL-50013' => 'notice',
+ 'VAL:ERRLVL-50014' => 'error',
+ 'VAL:ERRLVL-50015' => 'error',
+ 'VAL:ERRLVL-50016' => 'error',
+ 'VAL:ERRLVL-50017' => 'error',
+ 'VAL:ERRLVL-50018' => 'error',
+ 'VAL:ERRLVL-50020' => 'critical',
);
View
19 src/phpDocumentor/Plugin/Core/Messages/en.php
@@ -29,4 +29,23 @@
'PPC:ERR-50017' => 'The type for the %s tag in %s is "type"; isn\'t this an IDE default?',
'PPC:ERR-50018' => 'The type for the param tag %s in %s is either "type" or "unknown"; isn\'t this an IDE default?',
'PPC:ERR-50020' => 'Not found required tag "%s" in %s',
+
+ 'VAL:ERRLVL-50000' => 'error',
+ 'VAL:ERRLVL-50001' => 'error',
+ 'VAL:ERRLVL-50002' => 'error',
+ 'VAL:ERRLVL-50004' => 'warning',
+ 'VAL:ERRLVL-50005' => 'error',
+ 'VAL:ERRLVL-50006' => 'critical',
+ 'VAL:ERRLVL-50007' => 'error',
+ 'VAL:ERRLVL-50008' => 'error',
+ 'VAL:ERRLVL-50009' => 'error',
+ 'VAL:ERRLVL-50010' => 'error',
+ 'VAL:ERRLVL-50011' => 'error',
+ 'VAL:ERRLVL-50013' => 'notice',
+ 'VAL:ERRLVL-50014' => 'error',
+ 'VAL:ERRLVL-50015' => 'error',
+ 'VAL:ERRLVL-50016' => 'error',
+ 'VAL:ERRLVL-50017' => 'error',
+ 'VAL:ERRLVL-50018' => 'error',
+ 'VAL:ERRLVL-50020' => 'critical',
);
View
4 ...n/Core/Descriptor/Validator/Constraints/Classes/HasPackageWithSubpackageValidatorTest.php
@@ -75,7 +75,9 @@ public function testValidateHappyPath()
$this->fileDescriptor->shouldReceive('getTags')->andReturn($tagPackageCollection)->twice();
- $this->context->shouldReceive('addViolationAt')->once()->with('package', $this->constraint->message);
+ $this->context->shouldReceive('addViolationAt')
+ ->once()
+ ->with('package', $this->constraint->message, array(), null, null, $this->constraint->code);
$this->validator->validate($this->fileDescriptor, $this->constraint);
View
2 ...or/Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSinglePackageValidatorTest.php
@@ -65,7 +65,7 @@ public function testValidateHappyPath()
$packageCollection = new Collection(array('x', 'y'));
$tagCollection = new Collection(array('package' => $packageCollection));
$this->fileDescriptor->shouldReceive('getTags')->andReturn($tagCollection)->once();
- $this->context->shouldReceive('addViolationAt')->once()->with('package', $this->constraint->message);
+ $this->context->shouldReceive('addViolationAt')->once()->with('package', $this->constraint->message, array(), null, null, $this->constraint->code);
$this->validator->validate($this->fileDescriptor, $this->constraint);
}
View
2 ...Plugin/Core/Descriptor/Validator/Constraints/Classes/HasSingleSubpackageValidatorTest.php
@@ -67,7 +67,7 @@ public function testValidateHappyPath()
$this->fileDescriptor->shouldReceive('getTags')->andReturn($tagCollection)->once();
- $this->context->shouldReceive('addViolationAt')->once()->with('package', $this->constraint->message);
+ $this->context->shouldReceive('addViolationAt')->once()->with('package', $this->constraint->message, array(), null, null, $this->constraint->code);
$this->validator->validate($this->fileDescriptor, $this->constraint);
Something went wrong with that request. Please try again.