/** * get a full list of a class's inheritence hierarchy * * @param string $item * the item to examine * @return string[] * the class's inheritence hierarchy */ function get_class_types($item) { return GetClassTypes::from($item); }
/** * get a full list of an objects's inheritence hierarchy and other types * that it can satisfy * * @param object $item * the item to examine * @return string[] * the object's list of types */ public static function from($item) { // robustness! if (!is_object($item)) { return []; } $className = get_class($item); // our details are made up of this order: // // 1. details about the class // 2. that we are an object // 3. any magic methods that can be automatically taken advantage of // 4. the default fallback type $retval = array_merge(GetClassTypes::from($className), self::getObjectConditionalTypes($item)); return $retval; }
/** * does this string contain any class or interface names? * * @param string $item * the item to examine * @return string[] */ private static function detectClassNames($item) { $retval = []; // special case - is this a class name? if (class_exists($item)) { $retval = array_merge($retval, GetClassTypes::from($item), ['class' => 'class']); } else { if (interface_exists($item)) { $retval = array_merge($retval, GetClassTypes::from($item), ['interface' => 'interface']); } } // all done return $retval; }
/** * @covers ::from * @covers ::getClassHierarchy * @covers ::getInterfaceHierarchy * @dataProvider provideObjectsToTest */ public function testDetectsObjects($data, $expectedResult) { // ---------------------------------------------------------------- // setup your test $this->assertTrue(is_object($data)); // ---------------------------------------------------------------- // perform the change $actualResult = GetClassTypes::from($data); // ---------------------------------------------------------------- // test the results $this->assertEquals($expectedResult, $actualResult); }