| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * ownCloud - Calendar App | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author Georg Ehrke | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright 2016 Georg Ehrke <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * This library is free software; you can redistribute it and/or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * License as published by the Free Software Foundation; either | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * version 3 of the License, or any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * This library is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * GNU AFFERO GENERAL PUBLIC LICENSE for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * You should have received a copy of the GNU Affero General Public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * License along with this library.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | namespace OCA\Calendar\AppInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use OCA\Calendar\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use OCP\AppFramework\App; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use OCP\AppFramework\IAppContainer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | class Application extends App { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	 * @param array $params | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 33 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 	public function __construct($params=[]) { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 		parent::__construct('calendar', $params); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 		$container = $this->getContainer(); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 		$container->registerService('ContactController', function(IAppContainer $c) { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 			$request = $c->query('Request'); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 			$contacts = $c->getServer()->getContactsManager(); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 			return new Controller\ContactController($c->getAppName(), $request, $contacts); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 		}); | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 44 |  | View Code Duplication | 		$container->registerService('SettingsController', function(IAppContainer $c) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 			$request = $c->query('Request'); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 			$config = $c->getServer()->getConfig(); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  | 			$userSession = $c->getServer()->getUserSession(); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  | 			return new Controller\SettingsController($c->getAppName(), $request, $userSession, $config); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 		}); | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 51 |  | View Code Duplication | 		$container->registerService('ViewController', function(IAppContainer $c) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  | 			$request = $c->query('Request'); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | 			$userSession = $c->getServer()->getUserSession(); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | 			$config = $c->getServer()->getConfig(); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | 			return new Controller\ViewController($c->getAppName(), $request, $userSession, $config); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  | 		}); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	 * register navigation entry | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	public function registerNavigation() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$appName = $this->getContainer()->getAppName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		$server = $this->getContainer()->getServer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		$server->getNavigationManager()->add(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			'id' => $appName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			'order' => 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 			'href' => $server->getURLGenerator() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 				->linkToRoute('calendar.view.index'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			'icon' => $server->getURLGenerator() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 				->imagePath($appName, 'calendar.svg'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			'name' => $server->getL10N($appName)->t('Calendar'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |  | 
            
                        
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.