| Conditions | 3 |
| Paths | 1 |
| Total Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 17 | public function buildGrid() |
||
| 18 | { |
||
| 19 | $this |
||
| 20 | ->setDefaultOrder(new Order('updated_at', 'desc')) |
||
| 21 | ->addColumn('name', [ |
||
| 22 | 'title' => 'Nazwa użytkownika', |
||
| 23 | 'sortable' => true, |
||
| 24 | 'clickable' => function (Session $session) { |
||
| 25 | if ($session->userId) { |
||
|
|
|||
| 26 | return link_to_route('adm.users.save', $session->name, [$session->userId]); |
||
| 27 | } else { |
||
| 28 | return $session->robot ?: '--'; |
||
| 29 | } |
||
| 30 | }, |
||
| 31 | 'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE]) |
||
| 32 | ]) |
||
| 33 | ->addColumn('created_at', [ |
||
| 34 | 'title' => 'Data logowania', |
||
| 35 | 'sortable' => true, |
||
| 36 | 'render' => function (Session $session) { |
||
| 37 | return Carbon::createFromTimestamp($session->createdAt); |
||
| 38 | }, |
||
| 39 | 'decorator' => [$this->getDateTimeDecorator()] |
||
| 40 | ]) |
||
| 41 | ->addColumn('updated_at', [ |
||
| 42 | 'title' => 'Ostatnia aktywność', |
||
| 43 | 'sortable' => true, |
||
| 44 | 'render' => function (Session $session) { |
||
| 45 | return Carbon::createFromTimestamp($session->updatedAt); |
||
| 46 | }, |
||
| 47 | 'decorator' => [$this->getDateTimeDecorator()] |
||
| 48 | ]) |
||
| 49 | ->addColumn('ip', [ |
||
| 50 | 'title' => 'IP', |
||
| 51 | 'decorators' => [new Ip()], |
||
| 52 | 'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE, 'name' => 'sessions.ip']) |
||
| 53 | ]) |
||
| 54 | ->addColumn('path', [ |
||
| 55 | 'title' => 'Strona', |
||
| 56 | 'render' => function (Session $session) { |
||
| 57 | return link_to($session->path); |
||
| 58 | }, |
||
| 59 | 'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE]) |
||
| 60 | ]) |
||
| 61 | ->addColumn('browser', [ |
||
| 62 | 'title' => 'Przeglądarka' |
||
| 63 | ]) |
||
| 64 | ->addColumn('platform', [ |
||
| 65 | 'title' => 'System operacyjny' |
||
| 66 | ]) |
||
| 67 | ->addColumn('user_agent', [ |
||
| 68 | 'title' => 'User-agent', |
||
| 69 | 'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE, 'name' => 'sessions.browser']) |
||
| 70 | ]) |
||
| 71 | ->after(function (Row $row) { |
||
| 72 | $agent = new Agent(); |
||
| 73 | $agent->setUserAgent($row->raw('browser')); |
||
| 74 | |||
| 75 | $row->get('platform')->setValue($agent->platform()); |
||
| 76 | $row->get('browser')->setValue($agent->browser()); |
||
| 77 | $row->get('user_agent')->setValue($row->raw('browser')); |
||
| 78 | }); |
||
| 79 | } |
||
| 80 | } |
||
| 81 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: