for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/******************************************************************************
* An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
*
* Copyright (c) 2016 Richard Klees <[email protected]>
* This software is licensed under The MIT License. You should have received
* a copy of the license along with the code.
*/
namespace Lechimp\Dicto\Graph\Predicate;
use Lechimp\Dicto\Regexp;
use Lechimp\Dicto\Graph\Predicate;
use Lechimp\Dicto\Graph\Entity;
/**
* A predicate that is true if a property of the entity matches a regex.
class _PropertyMatches extends Predicate {
* @var string
protected $name;
protected $regexp;
public function __construct($name, Regexp $regexp) {
assert('is_string($name)');
$this->name = $name;
$this->regexp = $regexp;
$regexp
object<Lechimp\Dicto\Regexp>
string
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..
}
* @inheritdocs
public function _compile() {
$name = $this->name;
return function(Entity $e) use ($name) {
if (!$e->has_property($name)) {
return false;
return $this->regexp->match($e->property($name));
match
$this->regexp
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.
};
public function compile_to_source(array &$custom_closures) {
// If we didn't do this, backslash would not be escaped enough when
// eval'ing them.
$regexp = '%^'.str_replace("\\", "\\\\", $this->regexp->raw()).'$%';
raw
return
" \$value = \n".
" \$e->has_property(\"$name\")\n".
" && (preg_match(\"$regexp\", \$e->property(\"$name\")) == 1);\n";
public function for_types(array $existing_types) {
return $existing_types;
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..