{
/**
* The name of the group given to all constraints with no explicit group.
- *
- * @var string
*/
const DEFAULT_GROUP = 'Default';
/**
* Marks a constraint that can be put onto classes.
- *
- * @var string
*/
const CLASS_CONSTRAINT = 'class';
/**
* Marks a constraint that can be put onto properties.
- *
- * @var string
*/
const PROPERTY_CONSTRAINT = 'property';
/**
* Maps error codes to the names of their constants.
- *
- * @var array
*/
protected static $errorNames = array();
public static function getErrorName($errorCode)
{
if (!isset(static::$errorNames[$errorCode])) {
- throw new InvalidArgumentException(sprintf(
- 'The error code "%s" does not exist for constraint of type "%s".',
- $errorCode,
- get_called_class()
- ));
+ throw new InvalidArgumentException(sprintf('The error code "%s" does not exist for constraint of type "%s".', $errorCode, \get_called_class()));
}
return static::$errorNames[$errorCode];
// The "groups" option is added to the object lazily
$knownOptions['groups'] = true;
- if (is_array($options) && count($options) >= 1 && isset($options['value']) && !property_exists($this, 'value')) {
+ if (\is_array($options) && \count($options) >= 1 && isset($options['value']) && !property_exists($this, 'value')) {
$options[$this->getDefaultOption()] = $options['value'];
unset($options['value']);
}
- if (is_array($options)) {
+ if (\is_array($options)) {
reset($options);
}
- if (is_array($options) && count($options) > 0 && is_string(key($options))) {
+ if (\is_array($options) && \count($options) > 0 && \is_string(key($options))) {
foreach ($options as $option => $value) {
if (array_key_exists($option, $knownOptions)) {
$this->$option = $value;
$invalidOptions[] = $option;
}
}
- } elseif (null !== $options && !(is_array($options) && count($options) === 0)) {
+ } elseif (null !== $options && !(\is_array($options) && 0 === \count($options))) {
$option = $this->getDefaultOption();
if (null === $option) {
- throw new ConstraintDefinitionException(
- sprintf('No default option is configured for constraint %s', get_class($this))
- );
+ throw new ConstraintDefinitionException(sprintf('No default option is configured for constraint %s', \get_class($this)));
}
if (array_key_exists($option, $knownOptions)) {
}
}
- if (count($invalidOptions) > 0) {
- throw new InvalidOptionsException(
- sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), get_class($this)),
- $invalidOptions
- );
+ if (\count($invalidOptions) > 0) {
+ throw new InvalidOptionsException(sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), \get_class($this)), $invalidOptions);
}
- if (count($missingOptions) > 0) {
- throw new MissingOptionsException(
- sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), get_class($this)),
- array_keys($missingOptions)
- );
+ if (\count($missingOptions) > 0) {
+ throw new MissingOptionsException(sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), \get_class($this)), array_keys($missingOptions));
}
}
return;
}
- throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, get_class($this)), array($option));
+ throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, \get_class($this)), array($option));
}
/**
*
* @throws InvalidOptionsException If an invalid option name is given
*
- * @internal This method should not be used or overwritten in userland code.
+ * @internal this method should not be used or overwritten in userland code
*/
public function __get($option)
{
return $this->groups;
}
- throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, get_class($this)), array($option));
+ throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, \get_class($this)), array($option));
+ }
+
+ /**
+ * @param string $option The option name
+ *
+ * @return bool
+ */
+ public function __isset($option)
+ {
+ return 'groups' === $option;
}
/**
*/
public function addImplicitGroupName($group)
{
- if (in_array(self::DEFAULT_GROUP, $this->groups) && !in_array($group, $this->groups)) {
+ if (\in_array(self::DEFAULT_GROUP, $this->groups) && !\in_array($group, $this->groups)) {
$this->groups[] = $group;
}
}
*/
public function validatedBy()
{
- return get_class($this).'Validator';
+ return \get_class($this).'Validator';
}
/**