Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
22 | /** |
||
23 | * If you specify this value in seconds, it tells the completed job to queue another of itself |
||
24 | * x seconds ahead of time. |
||
25 | * |
||
26 | * @var mixed |
||
27 | * @config |
||
28 | */ |
||
29 | private static $regenerate_time = null; |
||
|
|||
30 | |||
31 | public function __construct() |
||
32 | { |
||
33 | // noop, but needed for QueuedJobsAdmin::createjob() to work |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | */ |
||
39 | public function getJobType() |
||
40 | { |
||
41 | return QueuedJob::QUEUED; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return string |
||
46 | */ |
||
47 | public function getTitle() |
||
48 | { |
||
49 | return _t(__CLASS__ . '.SYNCTITLE', 'Sync all groups and users from Active Directory, and set mappings up.'); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getSignature() |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @throws Exception |
||
62 | */ |
||
63 | View Code Duplication | public function validateRegenerateTime() |
|
64 | { |
||
65 | $regenerateTime = Config::inst()->get(LDAPAllSyncJob::class, 'regenerate_time'); |
||
66 | |||
67 | // don't allow this job to run less than every 15 minutes, as it could take a while. |
||
68 | if ($regenerateTime !== null && $regenerateTime < 900) { |
||
69 | throw new Exception('LDAPAllSyncJob::regenerate_time must be 15 minutes or greater'); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * {@inheritDoc} |
||
75 | */ |
||
76 | public function process() |
||
93 | } |
||
94 | } |
||
95 |
This check marks private properties in classes that are never used. Those properties can be removed.