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 |
||
21 | /** |
||
22 | * If you specify this value in seconds, it tells the completed job to queue another of itself |
||
23 | * x seconds ahead of time. |
||
24 | * |
||
25 | * @var mixed |
||
26 | * @config |
||
27 | */ |
||
28 | private static $regenerate_time = null; |
||
|
|||
29 | |||
30 | public function __construct() |
||
31 | { |
||
32 | // noop, but needed for QueuedJobsAdmin::createjob() to work |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @return string |
||
37 | */ |
||
38 | public function getJobType() |
||
39 | { |
||
40 | return QueuedJob::QUEUED; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return string |
||
45 | */ |
||
46 | public function getTitle() |
||
47 | { |
||
48 | return _t(__CLASS__ . '.SYNCTITLE', 'Sync all users from Active Directory'); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getSignature() |
||
55 | { |
||
56 | return md5(get_class($this)); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @throws Exception |
||
61 | */ |
||
62 | View Code Duplication | public function validateRegenerateTime() |
|
63 | { |
||
64 | $regenerateTime = Config::inst()->get( |
||
65 | LDAPMemberSyncJob::class, |
||
66 | 'regenerate_time' |
||
67 | ); |
||
68 | |||
69 | // don't allow this job to run less than every 15 minutes, as it could take a while. |
||
70 | if ($regenerateTime !== null && $regenerateTime < 900) { |
||
71 | throw new Exception('LDAPMemberSyncJob::regenerate_time must be 15 minutes or greater'); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * {@inheritDoc} |
||
77 | */ |
||
78 | public function process() |
||
95 | } |
||
96 | } |
||
97 |
This check marks private properties in classes that are never used. Those properties can be removed.