/** * @param string $type * @return array */ public static function resolve($type) { $name = Util::normalizeName($type); if (isset(self::$mappings[$name])) { return self::$mappings[$name]; } elseif (preg_match("/^(is|has)_/", $name) === 1) { return [Field::TYPE_FAKE, false, ['boolean']]; } elseif (preg_match("/_at\$/", $name) === 1) { return [Field::TYPE_FAKE, false, ['dateTime']]; } elseif (false !== strpos($name, '_')) { $name = str_replace('_', '', $name); return self::resolve($name); } else { return false; } }
<?php use Bravesheep\Dogmatist\Util; describe("Util", function () { describe("::normalizeName", function () { it("normalizes camelcased to underscored", function () { expect(Util::normalizeName("someCamelCasedExample"))->toBe('some_camel_cased_example'); expect(Util::normalizeName("FirstLetterCamelCased"))->toBe('first_letter_camel_cased'); expect(Util::normalizeName("Mixed_styleCamelCase"))->toBe('mixed_style_camel_case'); }); it("does not change underscored names", function () { expect(Util::normalizeName("test"))->toBe("test"); expect(Util::normalizeName("test_case"))->toBe("test_case"); }); }); describe("::isSystemClass", function () { it("checks for the array and object system classes", function () { expect(Util::isSystemClass('array'))->toBe(true); expect(Util::isSystemClass('object'))->toBe(true); expect(Util::isSystemClass('stdClass'))->toBe(true); }); it("does not return true for user classes", function () { expect(Util::isSystemClass('Bravesheep\\Dogmatist\\Dogmatist'))->toBe(false); }); }); describe("::isUserClass", function () { it("checks whether an identifier is not a system class", function () { expect(Util::isUserClass('Bravesheep\\Dogmatist\\Dogmatist'))->toBe(true); }); it("returns false for objects and arrays", function () { expect(Util::isUserClass('array'))->toBe(false);