| Conditions | 4 |
| Paths | 6 |
| Total Lines | 51 |
| Code Lines | 28 |
| 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 |
||
| 54 | private function getProjectMetadata($project) |
||
| 55 | { |
||
| 56 | // First, run through our project map. This is expected to return back |
||
| 57 | // to the project name if there is no defined mapping. |
||
| 58 | if ($this->container->hasParameter("app.project.$project")) { |
||
| 59 | $project = $this->container->getParameter("app.project.$project"); |
||
| 60 | } |
||
| 61 | |||
| 62 | // If this is a single-project setup, manually construct the metadata. |
||
| 63 | if ($this->container->getParameter("app.single_wiki")) { |
||
| 64 | return [ |
||
| 65 | 'dbname' => $this->container->getParameter('database_replica_name'), |
||
| 66 | 'url' => $this->container->getParameter('wiki_url'), |
||
| 67 | 'lang' => $this->container->getParameter('lang'), |
||
| 68 | 'name' => 'Xtools', // Not used? |
||
| 69 | ]; |
||
| 70 | } |
||
| 71 | |||
| 72 | // Grab the connection to the meta database |
||
| 73 | $this->client = $this->container |
||
| 74 | ->get('doctrine') |
||
| 75 | ->getManager('meta') |
||
| 76 | ->getConnection(); |
||
| 77 | |||
| 78 | // Create the query we're going to run against the meta database |
||
| 79 | $wikiQuery = $this->client->createQueryBuilder(); |
||
| 80 | $wikiQuery |
||
| 81 | ->select([ 'dbname', 'name', 'url', 'lang' ]) |
||
| 82 | ->from('wiki') |
||
| 83 | ->where($wikiQuery->expr()->eq('dbname', ':project')) |
||
| 84 | // The meta database will have the project's URL stored as https://en.wikipedia.org |
||
| 85 | // so we need to query for it accordingly, trying different variations the user |
||
| 86 | // might have inputted. |
||
| 87 | ->orwhere($wikiQuery->expr()->like('url', ':projectUrl')) |
||
| 88 | ->orwhere($wikiQuery->expr()->like('url', ':projectUrl2')) |
||
| 89 | ->setParameter('project', $project) |
||
| 90 | ->setParameter('projectUrl', "https://$project") |
||
| 91 | ->setParameter('projectUrl2', "https://$project.org"); |
||
| 92 | $wikiStatement = $wikiQuery->execute(); |
||
| 93 | |||
| 94 | // Fetch the wiki data |
||
| 95 | $wikis = $wikiStatement->fetchAll(); |
||
| 96 | |||
| 97 | // Return false if we can't find the wiki |
||
| 98 | if (count($wikis) < 1) { |
||
| 99 | return false; |
||
| 100 | } |
||
| 101 | |||
| 102 | // Otherwise, return the first result (in the rare event there are more than one). |
||
| 103 | return $wikis[0]; |
||
| 104 | } |
||
| 105 | |||
| 178 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.