Conditions | 6 |
Paths | 56 |
Total Lines | 57 |
Code Lines | 33 |
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 |
||
62 | public function index($type=3, $id=0, $limit=50, $offset=0, $showAll=null, |
||
63 | $oldestFirst=null, $search='') { |
||
64 | |||
65 | // in case this is called directly and not from the website use the |
||
66 | // internal state |
||
67 | if ($showAll === null) { |
||
68 | $showAll = $this->settings->getUserValue( |
||
69 | $this->userId, $this->appName,'showAll' |
||
70 | ) === '1'; |
||
71 | } |
||
72 | |||
73 | if ($oldestFirst === null) { |
||
74 | $oldestFirst = $this->settings->getUserValue( |
||
75 | $this->userId, $this->appName, 'oldestFirst' |
||
76 | ) === '1'; |
||
77 | } |
||
78 | |||
79 | $this->settings->setUserValue($this->userId, $this->appName, |
||
80 | 'lastViewedFeedId', $id); |
||
81 | $this->settings->setUserValue($this->userId, $this->appName, |
||
82 | 'lastViewedFeedType', $type); |
||
83 | |||
84 | $params = []; |
||
85 | |||
86 | // split search parameter on url space |
||
87 | $search = trim(urldecode($search)); |
||
88 | $search = preg_replace('/\s+/', ' ', $search); // remove multiple ws |
||
89 | if ($search === '') { |
||
90 | $search = []; |
||
91 | } else { |
||
92 | $search = explode(' ', $search); |
||
93 | } |
||
94 | |||
95 | try { |
||
96 | |||
97 | // the offset is 0 if the user clicks on a new feed |
||
98 | // we need to pass the newest feeds to not let the unread count get |
||
99 | // out of sync |
||
100 | if($offset === 0) { |
||
101 | $params['newestItemId'] = |
||
102 | $this->itemService->getNewestItemId($this->userId); |
||
103 | $params['feeds'] = $this->feedService->findAll($this->userId); |
||
104 | $params['starred'] = |
||
105 | $this->itemService->starredCount($this->userId); |
||
106 | } |
||
107 | |||
108 | $params['items'] = $this->itemService->findAll( |
||
109 | $id, $type, $limit, $offset, $showAll, $oldestFirst, |
||
110 | $this->userId, $search |
||
111 | ); |
||
112 | |||
113 | // this gets thrown if there are no items |
||
114 | // in that case just return an empty array |
||
115 | } catch(ServiceException $ex) {} |
||
116 | |||
117 | return $params; |
||
118 | } |
||
119 | |||
219 |