| Conditions | 3 |
| Paths | 3 |
| Total Lines | 22 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | protected static function getPostTypeFromName() |
||
| 37 | { |
||
| 38 | if (isset(static::$classNamePostType[static::class])) { |
||
| 39 | return static::$classNamePostType[static::class]; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Convert the class name to snake_case and cache on a static property |
||
| 44 | * to prevent evaluating more than once. |
||
| 45 | */ |
||
| 46 | $name = (new \ReflectionClass(static::class))->getShortName(); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Adapted from Str::snake() |
||
| 50 | * @link https://github.com/laravel/framework/blob/5.2/src/Illuminate/Support/Str.php |
||
| 51 | */ |
||
| 52 | if (! ctype_lower($name)) { |
||
| 53 | $name = strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', $name)); |
||
| 54 | } |
||
| 55 | |||
| 56 | return static::$classNamePostType[static::class] = $name; |
||
| 57 | } |
||
| 58 | } |
||
| 59 |