Conditions | 17 |
Paths | 443 |
Total Lines | 74 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
83 | public function fetch($url, $getFavicon=true, $lastModified=null, |
||
84 | $etag=null, $fullTextEnabled=false, |
||
85 | $basicAuthUser=null, $basicAuthPassword=null) { |
||
86 | try { |
||
87 | if ($basicAuthUser !== null && trim($basicAuthUser) !== '') { |
||
88 | $resource = $this->reader->discover($url, $lastModified, $etag, |
||
89 | $basicAuthUser, |
||
90 | $basicAuthPassword); |
||
91 | } else { |
||
92 | $resource = $this->reader->discover($url, $lastModified, $etag); |
||
93 | } |
||
94 | |||
95 | if (!$resource->isModified()) { |
||
96 | return [null, null]; |
||
97 | } |
||
98 | |||
99 | $location = $resource->getUrl(); |
||
100 | $etag = $resource->getEtag(); |
||
101 | $content = $resource->getContent(); |
||
102 | $encoding = $resource->getEncoding(); |
||
103 | $lastModified = $resource->getLastModified(); |
||
104 | |||
105 | $parser = $this->reader->getParser($location, $content, $encoding); |
||
106 | |||
107 | if ($fullTextEnabled) { |
||
108 | $parser->enableContentGrabber(); |
||
109 | } |
||
110 | |||
111 | $parsedFeed = $parser->execute(); |
||
112 | |||
113 | $feed = $this->buildFeed( |
||
114 | $parsedFeed, $url, $getFavicon, $lastModified, $etag, $location |
||
115 | ); |
||
116 | |||
117 | $items = []; |
||
118 | foreach($parsedFeed->getItems() as $item) { |
||
119 | $items[] = $this->buildItem($item, $parsedFeed); |
||
120 | } |
||
121 | |||
122 | return [$feed, $items]; |
||
123 | |||
124 | } catch(\Exception $ex){ |
||
125 | $msg = $ex->getMessage(); |
||
126 | |||
127 | if ($ex instanceof MalFormedXmlException) { |
||
128 | $msg = $this->l10n->t('Feed contains invalid XML'); |
||
129 | } else if ($ex instanceof SubscriptionNotFoundException) { |
||
130 | $msg = $this->l10n->t('Feed not found: either the website ' . |
||
131 | 'does not provide a feed or blocks access. To rule out ' . |
||
132 | 'blocking, try to download the feed on your server\'s ' . |
||
133 | 'command line using curl: curl http://the-feed.tld'); |
||
134 | } else if ($ex instanceof UnsupportedFeedFormatException) { |
||
135 | $msg = $this->l10n->t('Detected feed format is not supported'); |
||
136 | } else if ($ex instanceof InvalidCertificateException) { |
||
137 | $msg = $this->l10n->t('SSL Certificate is invalid'); |
||
138 | } else if ($ex instanceof InvalidUrlException) { |
||
139 | $msg = $this->l10n->t('Website not found'); |
||
140 | } else if ($ex instanceof MaxRedirectException) { |
||
141 | $msg = $this->l10n->t('More redirects than allowed, aborting'); |
||
142 | } else if ($ex instanceof MaxSizeException) { |
||
143 | $msg = $this->l10n->t('Bigger than maximum allowed size'); |
||
144 | } else if ($ex instanceof TimeoutException) { |
||
145 | $msg = $this->l10n->t('Request timed out'); |
||
146 | } else if ($ex instanceof UnauthorizedException) { |
||
|
|||
147 | $msg = $this->l10n->t('Required credentials for feed were ' . |
||
148 | 'either missing or incorrect'); |
||
149 | } else if ($ex instanceof ForbiddenException) { |
||
150 | $msg = $this->l10n->t('Forbidden to access feed'); |
||
151 | } |
||
152 | |||
153 | throw new FetcherException($msg); |
||
154 | } |
||
155 | |||
156 | } |
||
157 | |||
247 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.