Conditions | 5 |
Paths | 5 |
Total Lines | 54 |
Code Lines | 30 |
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 |
||
51 | public function databasePrepare($project = 'wiki') |
||
52 | { |
||
53 | if ($this->container->getParameter('app.single_wiki')) { |
||
54 | $dbName = $this->container->getParameter('database_replica_name'); |
||
55 | $wikiName = 'wiki'; |
||
56 | $url = $this->container->getParameter('wiki_url'); |
||
57 | } else { |
||
58 | // Grab the connection to the meta database |
||
59 | $this->client = $this->container->get('doctrine')->getManager('meta')->getConnection(); |
||
60 | |||
61 | // Create the query we're going to run against the meta database |
||
62 | $wikiQuery = $this->client->createQueryBuilder(); |
||
63 | $wikiQuery |
||
64 | ->select([ 'dbName', 'name', 'url', 'lang' ]) |
||
65 | ->from('wiki') |
||
66 | ->where($wikiQuery->expr()->eq('dbname', ':project')) |
||
67 | // The meta database will have the project's URL stored as https://en.wikipedia.org |
||
68 | // so we need to query for it accordingly, trying different variations the user |
||
69 | // might have inputted. |
||
70 | ->orwhere($wikiQuery->expr()->like('url', ':projectUrl')) |
||
71 | ->orwhere($wikiQuery->expr()->like('url', ':projectUrl2')) |
||
72 | ->setParameter('project', $project) |
||
73 | ->setParameter('projectUrl', "https://$project") |
||
74 | ->setParameter('projectUrl2', "https://$project.org"); |
||
75 | $wikiStatement = $wikiQuery->execute(); |
||
76 | |||
77 | // Fetch the wiki data |
||
78 | $wikis = $wikiStatement->fetchAll(); |
||
79 | |||
80 | // Throw an exception if we can't find the wiki |
||
81 | if (count($wikis) < 1) { |
||
82 | // TODO: Fix so that we're rendering a flash rather than dying... |
||
83 | throw new Exception("Unable to find project '$project'"); |
||
84 | // $this->container->get('controller')->addFlash('notice', ["nowiki", $project]); |
||
1 ignored issue
–
show
|
|||
85 | // return $this->container->redirectToRoute($route); |
||
1 ignored issue
–
show
|
|||
86 | } |
||
87 | |||
88 | // Grab the data we need out of it, using the first result |
||
89 | // (in the rare event there are more than one). |
||
90 | $dbName = $wikis[0]['dbName']; |
||
91 | $wikiName = $wikis[0]['name']; |
||
92 | $url = $wikis[0]['url']; |
||
93 | $lang = $wikis[0]['lang']; |
||
94 | } |
||
95 | |||
96 | if ($this->container->getParameter('app.is_labs') && substr($dbName, -2) != '_p') { |
||
97 | $dbName .= '_p'; |
||
98 | } |
||
99 | |||
100 | $this->dbName = $dbName; |
||
101 | $this->url = $url; |
||
102 | |||
103 | return [ 'dbName' => $dbName, 'wikiName' => $wikiName, 'url' => $url, 'lang' => $lang ]; |
||
104 | } |
||
105 | |||
157 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.