Skip to content

Allow to mark JSON properties & XML nodes as optional #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/Contains.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class Contains implements PatternExpander
{
const NAME = 'contains';

/**
* @var null|string
*/
Expand Down Expand Up @@ -62,12 +64,4 @@ public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'contains';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class Count implements PatternExpander
{
const NAME = 'count';

/**
* @var null|string
*/
Expand Down Expand Up @@ -51,12 +53,4 @@ public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'count';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/EndsWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class EndsWith implements PatternExpander
{
const NAME = 'endsWith';

/**
* @var
*/
Expand Down Expand Up @@ -77,12 +79,4 @@ protected function matchValue($value)
? mb_substr(mb_strtolower($value), -mb_strlen(mb_strtolower($this->stringEnding))) === mb_strtolower($this->stringEnding)
: mb_substr($value, -mb_strlen($this->stringEnding)) === $this->stringEnding;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'endsWith';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/GreaterThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class GreaterThan implements PatternExpander
{
const NAME = 'greaterThan';

/**
* @var
*/
Expand Down Expand Up @@ -55,12 +57,4 @@ public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'greaterThan';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/InArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class InArray implements PatternExpander
{
const NAME = 'inArray';

/**
* @var null|string
*/
Expand Down Expand Up @@ -51,12 +53,4 @@ public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'inArray';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/IsDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class IsDateTime implements PatternExpander
{
const NAME = 'isDateTime';

/**
* @var null|string
*/
Expand Down Expand Up @@ -52,12 +54,4 @@ protected function matchValue($value)
return false;
}
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'isDateTime';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/IsEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class IsEmail implements PatternExpander
{
const NAME = 'isEmail';

/**
* @var null|string
*/
Expand Down Expand Up @@ -51,12 +53,4 @@ protected function matchValue($value)
return false;
}
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'isEmail';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/IsEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class IsEmpty implements PatternExpander
{
const NAME = 'isEmpty';

private $error;

/**
Expand All @@ -32,12 +34,4 @@ public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'isEmpty';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/IsNotEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class IsNotEmpty implements PatternExpander
{
const NAME = 'isNotEmpty';

private $error;

/**
Expand All @@ -30,12 +32,4 @@ public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'isNotEmpty';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/IsUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class IsUrl implements PatternExpander
{
const NAME = 'isUrl';

/**
* @var null|string
*/
Expand Down Expand Up @@ -51,12 +53,4 @@ protected function matchValue($value)
return false;
}
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'isUrl';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/LowerThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class LowerThan implements PatternExpander
{
const NAME = 'lowerThan';

/**
* @var
*/
Expand Down Expand Up @@ -55,12 +57,4 @@ public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'lowerThan';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/MatchRegex.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class MatchRegex implements PatternExpander
{
const NAME = 'matchRegex';

/**
* @var null|string
*/
Expand Down Expand Up @@ -62,12 +64,4 @@ public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'matchRegex';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/OneOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class OneOf implements PatternExpander
{
const NAME = 'oneOf';

/**
* @var PatternExpander[]
*/
Expand Down Expand Up @@ -51,12 +53,4 @@ public function getError()
{
return $this->error;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'oneOf';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/Optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

final class Optional implements PatternExpander
{
const NAME = 'optional';

/**
* {@inheritdoc}
*/
Expand All @@ -21,12 +23,4 @@ public function getError()
{
return null;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'optional';
}
}
10 changes: 2 additions & 8 deletions src/Matcher/Pattern/Expander/StartsWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

final class StartsWith implements PatternExpander
{
const NAME = 'startsWith';

/**
* @var
*/
Expand Down Expand Up @@ -67,14 +69,6 @@ public function getError()
return $this->error;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'startsWith';
}

/**
* @param $value
* @return bool
Expand Down
7 changes: 0 additions & 7 deletions src/Matcher/Pattern/PatternExpander.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,4 @@ public function match($value);
* @return string|null
*/
public function getError();

/**
* Returns the name by which the expander is identified.
*
* @return string The name of the expander
*/
public function getName();
}
2 changes: 1 addition & 1 deletion src/Matcher/Pattern/TypePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getError()
public function hasExpander(string $expanderName)
{
foreach ($this->expanders as $expander) {
if ($expander->getName() === $expanderName) {
if ($expander::NAME === $expanderName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the problem, interface can't guarantee that Expander will have NAME constant. Please add is($name) method as I suggested in my previous comment

return true;
}
}
Expand Down
Loading