-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from norzechowicz/fix-text-matcher-null
Ignore strings that can be matched by other matchers in TextMatcher
- Loading branch information
Showing
9 changed files
with
172 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Coduo\PHPMatcher\Matcher\Pattern\Assert; | ||
|
||
class Json | ||
{ | ||
const TRANSFORM_QUOTATION_PATTERN = '/([^"])@([a-zA-Z0-9\.]+)@([^"])/'; | ||
const TRANSFORM_QUOTATION_REPLACEMENT = '$1"@$2@"$3'; | ||
|
||
/** | ||
* @param string $value | ||
* @return bool | ||
*/ | ||
public static function isValid($value) | ||
{ | ||
if (!is_string($value)) { | ||
return false; | ||
} | ||
|
||
if (null === json_decode($value) && JSON_ERROR_NONE !== json_last_error()) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Before checking json it wraps type patterns (@type@) with quotes ("@type@") | ||
* | ||
* @param string $value | ||
* @return bool | ||
*/ | ||
public static function isValidPattern($value) | ||
{ | ||
if (!is_string($value)) { | ||
return false; | ||
} | ||
|
||
return self::isValid(self::transformPattern($value)); | ||
} | ||
|
||
/** | ||
* Wraps placeholders which arent wrapped with quotes yet | ||
* | ||
* @param $pattern | ||
* @return mixed | ||
*/ | ||
public static function transformPattern($pattern) | ||
{ | ||
return preg_replace(self::TRANSFORM_QUOTATION_PATTERN, self::TRANSFORM_QUOTATION_REPLACEMENT, $pattern); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Coduo\PHPMatcher\Matcher\Pattern\Assert; | ||
|
||
class Xml | ||
{ | ||
/** | ||
* @param $value | ||
* @return bool | ||
*/ | ||
public static function isValid($value) | ||
{ | ||
if (!is_string($value)) { | ||
return false; | ||
|
||
} | ||
$xml = @simplexml_load_string($value); | ||
if (!$xml instanceof \SimpleXMLElement) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters