Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php  | 
            ||
| 17 | *  | 
            ||
| 18 | * @method \Joomla\StatsServer\WebApplication getApplication() Get the application object.  | 
            ||
| 19 | * @property-read \Joomla\StatsServer\WebApplication $app Application object  | 
            ||
| 20 | *  | 
            ||
| 21 | * @since 1.0  | 
            ||
| 22 | */  | 
            ||
| 23 | class SubmitControllerCreate extends AbstractController  | 
            ||
| 24 | { | 
            ||
| 25 | use ValidateVersion;  | 
            ||
| 26 | |||
| 27 | /**  | 
            ||
| 28 | * Statistics model object.  | 
            ||
| 29 | *  | 
            ||
| 30 | * @var StatsModel  | 
            ||
| 31 | * @since 1.0  | 
            ||
| 32 | */  | 
            ||
| 33 | private $model;  | 
            ||
| 34 | |||
| 35 | /**  | 
            ||
| 36 | * Allowed Database Types.  | 
            ||
| 37 | *  | 
            ||
| 38 | * @var array  | 
            ||
| 39 | * @since 1.0  | 
            ||
| 40 | */  | 
            ||
| 41 | private $databaseTypes = [  | 
            ||
| 42 | 'mysql',  | 
            ||
| 43 | 'mysqli',  | 
            ||
| 44 | 'pdomysql',  | 
            ||
| 45 | 'postgresql',  | 
            ||
| 46 | 'sqlazure',  | 
            ||
| 47 | 'sqlsrv',  | 
            ||
| 48 | ];  | 
            ||
| 49 | |||
| 50 | /**  | 
            ||
| 51 | * Constructor.  | 
            ||
| 52 | *  | 
            ||
| 53 | * @param StatsModel $model Statistics model object.  | 
            ||
| 54 | *  | 
            ||
| 55 | * @since 1.0  | 
            ||
| 56 | */  | 
            ||
| 57 | 1 | public function __construct(StatsModel $model)  | 
            |
| 61 | |||
| 62 | /**  | 
            ||
| 63 | * Execute the controller.  | 
            ||
| 64 | *  | 
            ||
| 65 | * @return boolean  | 
            ||
| 66 | *  | 
            ||
| 67 | * @since 1.0  | 
            ||
| 68 | */  | 
            ||
| 69 | 3 | public function execute()  | 
            |
| 135 | |||
| 136 | /**  | 
            ||
| 137 | * Check the CMS version.  | 
            ||
| 138 | *  | 
            ||
| 139 | * @param string $version The version number to check.  | 
            ||
| 140 | *  | 
            ||
| 141 | * @return string|boolean The version number on success or boolean false on failure.  | 
            ||
| 142 | *  | 
            ||
| 143 | * @since 1.0  | 
            ||
| 144 | */  | 
            ||
| 145 | 3 | View Code Duplication | private function checkCMSVersion(string $version)  | 
            
| 181 | |||
| 182 | /**  | 
            ||
| 183 | * Check the database type  | 
            ||
| 184 | *  | 
            ||
| 185 | * @param string $database The database type to check.  | 
            ||
| 186 | *  | 
            ||
| 187 | * @return string|boolean The database type on success or boolean false on failure.  | 
            ||
| 188 | *  | 
            ||
| 189 | * @since 1.0  | 
            ||
| 190 | */  | 
            ||
| 191 | 3 | private function checkDatabaseType(string $database)  | 
            |
| 200 | |||
| 201 | /**  | 
            ||
| 202 | * Check the PHP version  | 
            ||
| 203 | *  | 
            ||
| 204 | * @param string $version The version number to check.  | 
            ||
| 205 | *  | 
            ||
| 206 | * @return string|boolean The version number on success or boolean false on failure.  | 
            ||
| 207 | *  | 
            ||
| 208 | * @since 1.0  | 
            ||
| 209 | */  | 
            ||
| 210 | 3 | View Code Duplication | private function checkPHPVersion(string $version)  | 
            
| 211 | 	{ | 
            ||
| 212 | 3 | $version = $this->validateVersionNumber($version);  | 
            |
| 213 | |||
| 214 | // If the version number is invalid, don't go any further  | 
            ||
| 215 | 3 | if ($version === false)  | 
            |
| 216 | 		{ | 
            ||
| 217 | return false;  | 
            ||
| 218 | }  | 
            ||
| 219 | |||
| 220 | // We only track versions based on major.minor.patch so everything else is invalid  | 
            ||
| 221 | 3 | 		$explodedVersion = explode('.', $version); | 
            |
| 222 | |||
| 223 | 3 | if (count($explodedVersion) > 3)  | 
            |
| 224 | 		{ | 
            ||
| 225 | return false;  | 
            ||
| 226 | }  | 
            ||
| 227 | |||
| 228 | // Import the valid release listing  | 
            ||
| 229 | 3 | $path = APPROOT . '/versions/php.json';  | 
            |
| 230 | |||
| 231 | 3 | if (!file_exists($path))  | 
            |
| 232 | 		{ | 
            ||
| 233 | 			throw new \RuntimeException('Missing PHP release listing', 500); | 
            ||
| 234 | }  | 
            ||
| 235 | |||
| 236 | 3 | $validVersions = json_decode(file_get_contents($path), true);  | 
            |
| 237 | |||
| 238 | // Check that the version is in our valid release list  | 
            ||
| 239 | 3 | if (!in_array($version, $validVersions))  | 
            |
| 240 | 		{ | 
            ||
| 241 | return false;  | 
            ||
| 247 | 
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.