Issues (3)

sandbox.php (2 issues)

1
<?php
2
/*
3
 * This file is part of the Adlogix package.
4
 *
5
 * (c) Allan Segebarth <[email protected]>
6
 * (c) Jean-Jacques Courtens <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
use Adlogix\EventScheduler\BasicEvent;
13
use Adlogix\EventScheduler\TemporalExpression\Collection\Intersection;
14
use Adlogix\EventScheduler\TemporalExpression\Collection\Union;
15
use Adlogix\EventScheduler\TemporalExpression\DayInWeek;
16
use Adlogix\EventScheduler\TemporalExpression\Difference;
17
use Adlogix\EventScheduler\TemporalExpression\From;
18
use Adlogix\EventScheduler\TemporalExpression\TemporalExpressionInterface;
19
use Adlogix\EventScheduler\TemporalExpression\Until;
20
use Adlogix\EventScheduler\TemporalExpression\WeekInYear;
21
22
require "vendor/autoload.php";
23
24
final class FixedDay implements TemporalExpressionInterface
25
{
26
    /**
27
     * @var DateTimeInterface
28
     */
29
    private $date;
30
31
    /**
32
     * @param DateTimeInterface $date
33
     */
34
    public function __construct(DateTimeInterface $date)
35
    {
36
        $this->date = $date;
37
    }
38
39
    public function includes(DateTimeInterface $date): bool
40
    {
41
        $intersection = (new Intersection())
42
            ->addElement(new From($this->date))
43
            ->addElement(new Until($this->date));
44
45
        return $intersection->includes($date);
46
    }
47
}
48
49
$scheduler = new \Adlogix\EventScheduler\Scheduler();
50
51
$titleFixedDayExpression = new Union();
52
$titleFixedDayExpression
53
    ->addElement(new FixedDay(new DateTime('2018-06-01')))
54
    ->addElement(new FixedDay(new DateTime('2018-08-02')))
55
    ->addElement(new FixedDay(new DateTime('2018-09-22')));
56
57
$titleExpression = new Intersection();
58
$titleExpression
59
    ->addElement(new From(new DateTime('2018-02-01')))
60
    ->addElement(
61
        (new Union())
62
            ->addElement(DayInWeek::saturday())
63
            ->addElement(DayInWeek::wednesday())
64
            ->addElement($titleFixedDayExpression)
65
    );
66
67
$holidayExpression = new WeekInYear(38);
68
69
70
$expression = new Difference($titleExpression, $holidayExpression);
71
72
73
$myEvent = new BasicEvent('test');
74
$scheduler->schedule($myEvent, $expression);
75
76
77
//echo $scheduler->nextOccurrence($myEvent, new DateTime(), (new DateTime())->modify('+8 month'))->format('Y-m-d') . "\n";
78
79
echo var_export($scheduler->isOccurring($myEvent, new DateTime('2018-06-01'))) . "\n";
0 ignored issues
show
Are you sure the usage of var_export($scheduler->i...ateTime('2018-06-01'))) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
80
echo var_export($scheduler->isOccurring($myEvent, new DateTime('2018-05-16'))) . "\n";
0 ignored issues
show
Are you sure the usage of var_export($scheduler->i...ateTime('2018-05-16'))) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
81
82
83
$dates = $scheduler->dates($myEvent,
84
    new \Adlogix\EventScheduler\DateRange\DateRange(new DateTime('2018-01-01'), new DateTime('2018-12-31')));
85
foreach ($dates as $date) {
86
    echo "- " . $date->format('Y-m-d') . "\n";
87
}
88