Conditions | 13 |
Paths | 21 |
Total Lines | 49 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
33 | final public function description(Event $event): void |
||
34 | { |
||
35 | if (empty($event->data) || empty($event->data['meta'])) { |
||
36 | return; |
||
37 | } |
||
38 | |||
39 | global $ID; |
||
40 | $source = $this->getConf('keyword_source'); |
||
41 | if (empty($source)) { |
||
42 | $source = 'abstract'; |
||
43 | } |
||
44 | |||
45 | $metaContent = ''; |
||
46 | switch ($source) { |
||
47 | case KEYWORD_SOURCE_ABSTRACT: |
||
48 | if (auth_quickaclcheck($ID) < AUTH_READ) { |
||
49 | // don't add meta header when user has no read permissions |
||
50 | return; |
||
51 | } |
||
52 | $d = p_get_metadata($ID, 'description'); |
||
53 | if (empty($d)) { |
||
54 | return; |
||
55 | } |
||
56 | $metaContent = str_replace("\n", " ", $d['abstract']); |
||
57 | if (empty($metaContent)) { |
||
58 | return; |
||
59 | } |
||
60 | break; |
||
61 | case KEYWORD_SOURCE_GLOBAL: |
||
62 | $metaContent = $this->getConf('global_description'); |
||
63 | if (empty($metaContent)) { |
||
64 | return; |
||
65 | } |
||
66 | break; |
||
67 | case KEYWORD_SOURCE_SYNTAX: |
||
68 | if (auth_quickaclcheck($ID) < AUTH_READ) { |
||
69 | // don't add meta header when user has no read permissions |
||
70 | return; |
||
71 | } |
||
72 | $metadata = p_get_metadata($ID); |
||
73 | $metaContent = $metadata['plugin_description']['keywords']; |
||
74 | if (empty($metaContent)) { |
||
75 | return; |
||
76 | } |
||
77 | break; |
||
78 | |||
79 | } |
||
80 | |||
81 | $event->data['meta'][] = ["name" => "description", "content" => $metaContent]; |
||
82 | } |
||
84 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: