| Total Complexity | 146 |
| Total Lines | 215 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Base often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Base, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | abstract class Base |
||
| 21 | { |
||
| 22 | private $locale; |
||
| 23 | |||
| 24 | |||
| 25 | /** |
||
| 26 | * Initializes the translation object. |
||
| 27 | * |
||
| 28 | * @param string $locale Locale string, e.g. en or en_GB |
||
| 29 | */ |
||
| 30 | public function __construct( string $locale ) |
||
| 31 | { |
||
| 32 | if( preg_match( '/^[a-z]{2,3}(_[A-Z]{2})?$/', $locale ) !== 1 ) { |
||
| 33 | throw new \Aimeos\Base\Translation\Exception( sprintf( 'Invalid locale "%1$s"', $locale ) ); |
||
| 34 | } |
||
| 35 | |||
| 36 | $this->locale = (string) $locale; |
||
| 37 | } |
||
| 38 | |||
| 39 | |||
| 40 | /** |
||
| 41 | * Returns the current locale string. |
||
| 42 | * |
||
| 43 | * @return string ISO locale string |
||
| 44 | */ |
||
| 45 | public function getLocale() : string |
||
| 48 | } |
||
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * Returns the location of the translation file. |
||
| 53 | * If the requested file does exists (eg: de_DE) the implementation |
||
| 54 | * will check for "de" and will return that location as fallback. |
||
| 55 | * |
||
| 56 | * @param string[] $paths Paths of the translation files |
||
| 57 | * @param string $locale Locale to be used |
||
| 58 | * @return string[] List of locations to the translation files |
||
| 59 | * @throws \Aimeos\Base\Translation\Exception If translation file doesn't exist |
||
| 60 | */ |
||
| 61 | protected function getTranslationFileLocations( array $paths, string $locale ) : array |
||
| 86 | } |
||
| 87 | |||
| 88 | |||
| 89 | /** |
||
| 90 | * Returns the plural index number to be used for the plural translation. |
||
| 91 | * |
||
| 92 | * @param int $number Quantity to find the plural index |
||
| 93 | * @param string $locale Locale to be used |
||
| 94 | * @return int Number of the plural index |
||
| 95 | */ |
||
| 96 | protected function getPluralIndex( int $number, string $locale ) : int |
||
| 107 | } |
||
| 108 | |||
| 109 | |||
| 110 | /** |
||
| 111 | * Returns the plural index for the given locale. |
||
| 112 | * |
||
| 113 | * @param int $number Quantity to find the plural index |
||
| 114 | * @param string $locale Locale to be used |
||
| 115 | * @return int Number of the plural index |
||
| 116 | * |
||
| 117 | * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) |
||
| 118 | * @license New BSD License, https://opensource.org/licenses/BSD-3-Clause |
||
| 119 | */ |
||
| 120 | protected function index( int $number, string $locale ) : int |
||
| 239 |