| Conditions | 3 |
| Paths | 4 |
| Total Lines | 69 |
| 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 |
||
| 67 | public function testScheduledExecutionInterval() |
||
| 68 | { |
||
| 69 | $test = new TestScheduledDataObject; |
||
| 70 | |||
| 71 | $test->Title = 'Test execute at custom interval sizes'; |
||
| 72 | $test->write(); |
||
| 73 | |||
| 74 | $test->FirstExecution = '1980-09-22 09:15:00'; |
||
| 75 | $test->ExecuteEvery = 'Minute'; |
||
| 76 | |||
| 77 | $test->write(); |
||
| 78 | |||
| 79 | // should now have a job |
||
| 80 | $this->assertTrue($test->ScheduledJobID > 0, 'Scheduled job has not been created'); |
||
| 81 | // should default the ExecuteInterval |
||
| 82 | $this->assertEquals(1, $test->ExecuteInterval, 'ExecuteInterval did not default to 1'); |
||
| 83 | |||
| 84 | // should check the interval in code also |
||
| 85 | $test->ExecuteInterval = 0; |
||
| 86 | $test->write(); |
||
| 87 | |||
| 88 | $jobId = $test->ScheduledJobID; |
||
| 89 | |||
| 90 | // execute said job |
||
| 91 | $job = $test->ScheduledJob(); |
||
| 92 | $job->execute(); |
||
| 93 | |||
| 94 | // reload the test object and make sure its job has now changed |
||
| 95 | $test = DataObject::get_by_id(TestScheduledDataObject::class, $test->ID); |
||
| 96 | |||
| 97 | $this->assertNotEquals($test->ScheduledJobID, $jobId); |
||
| 98 | $this->assertEquals('EXECUTED', $test->Message); |
||
| 99 | |||
| 100 | $job = $test->ScheduledJob(); |
||
| 101 | |||
| 102 | // should reschedule in 1 minute time |
||
| 103 | $expectedMinutes = date('i', time()); |
||
| 104 | $expectedMinutes = intval($expectedMinutes, 10); |
||
| 105 | if ($expectedMinutes + 1 > 59) { // Wrap around the hour |
||
| 106 | $expectedMinutes = $expectedMinutes - 59; |
||
| 107 | } |
||
| 108 | $scheduledMinutes = substr($job->StartAfter, 14, 2); |
||
| 109 | $scheduledMinutes = intval($scheduledMinutes, 10); |
||
| 110 | |||
| 111 | $this->assertEquals($expectedMinutes + 1, $scheduledMinutes, 'Did not reschedule 1 minute later'); |
||
| 112 | |||
| 113 | // test a custom interval of 3 minutes |
||
| 114 | |||
| 115 | $test->ExecuteInterval = 3; |
||
| 116 | $test->write(); |
||
| 117 | |||
| 118 | $job = $test->ScheduledJob(); |
||
| 119 | $job->execute(); |
||
| 120 | |||
| 121 | $test = DataObject::get_by_id(TestScheduledDataObject::class, $test->ID); |
||
| 122 | |||
| 123 | $job = $test->ScheduledJob(); |
||
| 124 | |||
| 125 | // should reschedule in 3 minutes time |
||
| 126 | $expectedMinutes = date('i', time()); |
||
| 127 | $expectedMinutes = intval($expectedMinutes, 10); |
||
| 128 | if ($expectedMinutes + 3 > 59) { |
||
| 129 | $expectedMinutes = $expectedMinutes - 59; |
||
| 130 | } |
||
| 131 | $scheduledMinutes = substr($job->StartAfter, 14, 2); |
||
| 132 | $scheduledMinutes = intval($scheduledMinutes, 10); |
||
| 133 | |||
| 134 | $this->assertEquals($expectedMinutes + 3, $scheduledMinutes, 'Did not reschedule 3 minutes later'); |
||
| 135 | } |
||
| 136 | } |
||
| 137 |
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@propertyannotation 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.