/** * throws exceptions if $item is not a stringy data type * * @param mixed $item * the container to check * @param string $exception * the class to use when throwing an exception * @return void */ public static function check($item, $exception = E4xx_UnsupportedType::class) { // make sure we have a stringy type if (!IsStringy::check($item)) { throw new $exception(SimpleType::from($item)); } }
/** * create a read-only, string guarantee from another piece of data * * @param mixed $data * the data to wrap */ public function __construct($data) { // we only assign our data if we have been given something // that is string-like if (IsStringy::check($data)) { $this->data = (string) $data; $this->isEmpty = false; } }
/** * @covers ::__invoke * @covers ::check * @covers ::checkMixed */ public function testCanDetectObjectsThatCanBecomeStrings() { // ---------------------------------------------------------------- // setup your test $obj = new IsStringy(); $data = new IsStringyTest_Target1(); // ---------------------------------------------------------------- // perform the change $actualResult1 = $obj($data); $actualResult2 = IsStringy::check($data); // ---------------------------------------------------------------- // test the results $this->assertTrue($actualResult1); $this->assertTrue($actualResult2); }