| Conditions | 8 |
| Paths | 24 |
| Total Lines | 59 |
| Lines | 12 |
| Ratio | 20.34 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 15 | public function __construct($title) |
||
| 16 | { |
||
| 17 | $this->settings = \Settings::getInstance(); |
||
|
|
|||
| 18 | $this->loader = new \Twig_Loader_Filesystem(dirname(__FILE__).'/../templates'); |
||
| 19 | $twigSettings = array('cache' => '/var/php_cache/twig'); |
||
| 20 | if(isset($GLOBALS['TWIG_CACHE'])) |
||
| 21 | { |
||
| 22 | $twigSettings = $twigSettings = array('cache' => $GLOBALS['TWIG_CACHE']); |
||
| 23 | } |
||
| 24 | $this->twig = new \Twig_Environment($this->loader, $twigSettings); |
||
| 25 | $this->content = array('pageTitle' => $title); |
||
| 26 | $this->user = \FlipSession::getUser(); |
||
| 27 | $this->content['header'] = array(); |
||
| 28 | $this->content['header']['sites'] = array(); |
||
| 29 | $wwwUri = $this->settings->getGlobalSetting('www_url', 'https://www.burningflipside.com'); |
||
| 30 | $this->content['header']['sites']['Profiles'] = $this->settings->getGlobalSetting('profiles_url', 'https://profiles.burningflipside.com/'); |
||
| 31 | $this->content['header']['sites']['WWW'] = $wwwUri; |
||
| 32 | $this->content['header']['sites']['Pyropedia'] = $this->settings->getGlobalSetting('wiki_url', 'https://wiki.burningflipside.com'); |
||
| 33 | $this->content['header']['sites']['Secure'] = $this->settings->getGlobalSetting('secure_url', 'https://secure.burningflipside.com/'); |
||
| 34 | |||
| 35 | $aboutUrl = $this->settings->getGlobalSetting('about_url', $wwwUri.'/about'); |
||
| 36 | $this->content['header']['right']['About'] = array( |
||
| 37 | 'url' => $aboutUrl, |
||
| 38 | 'menu' => $this->settings->getGlobalSetting('about_menu', array( |
||
| 39 | 'Burning Flipside' => $wwwUri.'/about/event', |
||
| 40 | 'AAR, LLC' => $wwwUri.'/organization/aar', |
||
| 41 | 'Privacy Policy' => $wwwUri.'/about/privacy' |
||
| 42 | ))); |
||
| 43 | |||
| 44 | $this->profilesUrl = $this->settings->getGlobalSetting('profiles_url', 'https://profiles.burningflipside.com/'); |
||
| 45 | $this->registerUrl = $this->settings->getGlobalSetting('register_url', $this->profilesUrl.'/register.php'); |
||
| 46 | $this->resetUrl = $this->settings->getGlobalSetting('reset_url', $this->profilesUrl.'/reset.php'); |
||
| 47 | $this->loginUrl = $this->settings->getGlobalSetting('login_url', $this->profilesUrl.'/login.php'); |
||
| 48 | |||
| 49 | View Code Duplication | if($this->user === false || $this->user === null) |
|
| 50 | { |
||
| 51 | if(isset($_SERVER['REQUEST_URI']) && strstr($_SERVER['REQUEST_URI'], 'logout.php') === false) |
||
| 52 | { |
||
| 53 | $this->addLink('Login', $this->loginUrl); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | else |
||
| 57 | { |
||
| 58 | $this->addLink('Logout', $this->settings->getGlobalSetting('logout_url', $this->profilesUrl.'/logout.php')); |
||
| 59 | $this->addLinks(); |
||
| 60 | } |
||
| 61 | |||
| 62 | $this->minified = 'min'; |
||
| 63 | $this->cdn = 'cdn'; |
||
| 64 | if($this->settings->getGlobalSetting('use_minified', true) == false) |
||
| 65 | { |
||
| 66 | $this->minified = 'no'; |
||
| 67 | } |
||
| 68 | if($this->settings->getGlobalSetting('use_cdn', true) == false) |
||
| 69 | { |
||
| 70 | $this->cdn = 'no'; |
||
| 71 | $this->content['useCDN'] = false; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 226 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: