| Conditions | 9 |
| Paths | 60 |
| Total Lines | 68 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 30 | protected $subMenu = []; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Creates a new project controller instance. |
||
| 34 | * |
||
| 35 | * @return void |
||
| 36 | */ |
||
| 37 | public function __construct() |
||
| 38 | { |
||
| 39 | $this->subMenu = [ |
||
| 40 | 'yours' => [ |
||
| 41 | 'title' => trans('dashboard.projects.yours'), |
||
| 42 | 'url' => route('dashboard.projects.index'), |
||
| 43 | 'icon' => 'fa fa-edit', |
||
| 44 | 'active' => false, |
||
| 45 | ], |
||
| 46 | 'starred' => [ |
||
| 47 | 'title' => trans('dashboard.projects.starred'), |
||
| 48 | 'url' => route('dashboard.projects.starred'), |
||
| 49 | 'icon' => 'fa fa-umbrella', |
||
| 50 | 'active' => false, |
||
| 51 | ], |
||
| 52 | 'explore' => [ |
||
| 53 | 'title' => trans('dashboard.projects.explore'), |
||
| 54 | 'url' => route('explore.index'), |
||
| 55 | 'icon' => 'fa fa-eye', |
||
| 56 | 'active' => false, |
||
| 57 | ], |
||
| 58 | ]; |
||
| 59 | |||
| 60 | View::share([ |
||
| 61 | 'sub_menu' => $this->subMenu, |
||
| 62 | 'sub_title' => trans_choice('dashboard.projects.projects', 2), |
||
| 63 | ]); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Displays the explore page. |
||
| 68 | * |
||
| 69 | * @return \Illuminate\View\View |
||
| 70 | */ |
||
| 71 | public function indexAction() |
||
| 72 | { |
||
| 73 | $this->subMenu['explore']['active'] = true; |
||
| 74 | |||
| 75 | $today = Date::now(); |
||
| 76 | $startDate = Date::now(); |
||
| 77 | |||
| 78 | // Check if we have another starting date |
||
| 79 | if (Binput::has('start_date')) { |
||
| 80 | try { |
||
| 81 | // If date provided is valid |
||
| 82 | $oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date')); |
||
| 83 | |||
| 84 | // If trying to get a future date fallback to today |
||
| 85 | if ($today->gt($oldDate)) { |
||
| 86 | $startDate = $oldDate; |
||
| 87 | } |
||
| 88 | } catch (Exception $e) { |
||
| 89 | // Fallback to today |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | $daysToShow = Setting::get('app_issue_days', 0) - 1; |
||
| 94 | if ($daysToShow < 0) { |
||
| 95 | $daysToShow = 0; |
||
| 96 | $issueDays = []; |
||
| 97 | } else { |
||
| 98 | $issueDays = range(0, $daysToShow); |
||
| 182 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: