protected final function dataTypeCheck($value, $variableName, $soft) { if (!is_numeric($value) || static::$strictNumberCheck && is_string($value)) { return static::handleTypeError($this->getTypeString(), $value, $variableName, $soft); } if (!$this->checkRange($value, $variableName, $soft)) { return None::getInstance(); } return $this->subTypeCheck($value, $variableName, $soft); }
protected final function dataTypeCheck($value, $variableName, $soft) { if (!is_string($value)) { return static::handleTypeError($this->getTypeString(), $value, $variableName, $soft); } if ($this->validatorRegex) { if (!preg_match($this->validatorRegex, $value)) { if ($soft) { return None::getInstance(); } throw new TypeError("Value named: {$variableName} with data: \"{$value}\" does not conform to regex: {$this->validatorRegex}"); } } return $this->additionalCheck($value, $variableName, $soft); }
/** * append() をテストします. * 以下を確認します. * * - 任意のスカラー値および Node が追加できること * - null および None を指定した場合, 変化がない (追加されない) こと * - コンテナを追加した場合, 自身ではなくその子ノードが追加されること * * @covers Peach\Markup\Container::append */ public function testAppend() { $nList = new NodeList(); $nList->append("foo"); $nList->append("bar"); $nList->append("baz"); $test = $this->test; $obj = $this->object; $obj->append(null); $obj->append("TEXT"); // (count: 1) $obj->append(new EmptyElement("test")); // (count: 2) $obj->append(None::getInstance()); // added nothing (count: 2) $obj->append($nList); // added 3 nodes (count: 5) $obj->append(array("A", "B", array("C", "D"))); // added 4 nodes (count: 9) $test->assertSame(9, count($obj->getChildNodes())); }
protected function dataTypeCheck($value, $variableName, $soft) { $isObject = is_object($value); $isArray = is_array($value); if (!($isObject || $isArray)) { if ($soft) { return None::getInstance(); } throw new TypeError("Type must be object, type of value named: {$variableName} given: " . gettype($value) . " with data: " . static::safePrint($value)); } //Set missing fields to null, let the child type check if it accepts it. foreach ($this->childrenType as $key => $element) { if ($isArray && !array_key_exists($key, $value)) { $value[$key] = null; } else { if ($isObject && !property_exists($value, $key)) { $value->{$key} = null; } } //throw new TypeError("Required property: $key is missing from object: $variableName"); } if ($this->childrenType !== null) { foreach ($value as $key => $element) { if (!isset($this->childrenType[$key])) { throw new TypeError("Property {$key} in array: {$variableName} does not have a validator Type"); } //$actualValue = $this->childrenType[$key]->check($element, "{$variableName}:{{$key}}"); $actualValue = $this->childrenType[$key]->check($element, "{$variableName}:{$key}"); if ($isArray) { $value[$key] = $actualValue; } else { $value->{$key} = $actualValue; } } } return $value; }
/** * @inheritdoc * @see QueryInterface::find * This is an constant on perceived nothings * @return None */ public final function find(callable $hof) { return None::getInstance(); }
/** * @param $filePath * @return Option */ public static function ofFile($filePath) { return file_exists($filePath) ? new Some($filePath) : None::getInstance(); }
/** * @return None */ function None() { return None::getInstance(); }
/** * @inheritdoc */ public function find(callable $hof) { return $hof($this->value, 0, $this) ? new Some($this->value) : None::getInstance(); }
/** * @inheritdoc * @return None */ public function left() { return None::getInstance(); }
/** * getInstance() のテストです. 以下を確認します. * * - None のインスタンスを返すことを確認します. * - 常に同一のオブジェクトを返すことを確認します. * * @covers Peach\Markup\None::getInstance */ public function testGetInstance() { $obj = None::getInstance(); $this->assertSame("Peach\\Markup\\None", get_class($obj)); $this->assertSame($this->object, $obj); }
/** * 結果に何も追加されないことを確認します。 * * @covers Peach\Markup\DefaultContext::handleNone */ public function testHandleNone() { $none = None::getInstance(); $obj = $this->object; $obj->handle($none); $this->assertSame("", $obj->getResult()); }
/** * handleNone() のテストです. * * @covers Peach\Markup\DebugContext::handleNone * @covers Peach\Markup\DebugContext::append */ public function testHandleNone() { $expected = "None\r\n"; $context = $this->object; $none = None::getInstance(); $this->expectOutputString($expected); $context->handleNone($none); $this->assertSame($expected, $context->getResult()); }
/** * @inheritdoc * @return Some|None */ public function filterNot(callable $hof) { return !call_user_func($hof, $this->x, 0, $this) ? $this : None::getInstance(); }
/** * @inheritdoc * @return None */ public function right() { return None::getInstance(); }