Conditions | 1 |
Paths | 1 |
Total Lines | 58 |
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 |
||
68 | public function testScheduledExecutionInterval() |
||
69 | { |
||
70 | $test = new TestScheduledDataObject(); |
||
71 | |||
72 | $test->Title = 'Test execute at custom interval sizes'; |
||
73 | $test->write(); |
||
74 | |||
75 | $test->FirstExecution = '1980-09-22 09:15:00'; |
||
76 | $test->ExecuteEvery = 'Minute'; |
||
77 | |||
78 | $test->write(); |
||
79 | |||
80 | // should now have a job |
||
81 | $this->assertTrue($test->ScheduledJobID > 0, 'Scheduled job has not been created'); |
||
82 | // should default the ExecuteInterval |
||
83 | $this->assertEquals(1, $test->ExecuteInterval, 'ExecuteInterval did not default to 1'); |
||
84 | |||
85 | // should check the interval in code also |
||
86 | $test->ExecuteInterval = 0; |
||
87 | $test->write(); |
||
88 | |||
89 | $jobId = $test->ScheduledJobID; |
||
90 | |||
91 | // execute said job |
||
92 | $job = $test->ScheduledJob(); |
||
93 | $job->execute(); |
||
94 | |||
95 | // reload the test object and make sure its job has now changed |
||
96 | $test = DataObject::get_by_id(TestScheduledDataObject::class, $test->ID); |
||
97 | |||
98 | $this->assertNotEquals($test->ScheduledJobID, $jobId); |
||
99 | $this->assertEquals('EXECUTED', $test->Message); |
||
100 | |||
101 | $job = $test->ScheduledJob(); |
||
102 | |||
103 | $expected = new DateTime('+1 minute'); |
||
104 | $actual = new DateTime($job->StartAfter); |
||
105 | |||
106 | // Allow within 1 second. |
||
107 | $this->assertLessThanOrEqual(1, abs($actual->diff($expected)->s), 'Did not reschedule 1 minute later'); |
||
108 | |||
109 | // test a custom interval of 3 minutes |
||
110 | |||
111 | $test->ExecuteInterval = 3; |
||
112 | $test->write(); |
||
113 | |||
114 | $job = $test->ScheduledJob(); |
||
115 | $job->execute(); |
||
116 | |||
117 | $test = DataObject::get_by_id(TestScheduledDataObject::class, $test->ID); |
||
118 | |||
119 | $job = $test->ScheduledJob(); |
||
120 | |||
121 | $expected = new DateTime('+3 minutes'); |
||
122 | $actual = new DateTime($job->StartAfter); |
||
123 | |||
124 | $this->assertLessThanOrEqual(1, abs($actual->diff($expected)->s), 'Did not reschedule 3 minutes later'); |
||
125 | } |
||
126 | } |
||
127 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.