ICalendarController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
B user() 0 25 4
B project() 0 25 2
A renderCalendar() 0 10 1
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
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
namespace Jitamin\Http\Controllers;
13
14
use Eluceo\iCal\Component\Calendar as iCalendar;
15
use Jitamin\Filter\TaskAssigneeFilter;
16
use Jitamin\Filter\TaskProjectFilter;
17
use Jitamin\Filter\TaskStatusFilter;
18
use Jitamin\Formatter\TaskICalFormatter;
19
use Jitamin\Foundation\Exceptions\AccessForbiddenException;
20
use Jitamin\Foundation\Filter\QueryBuilder;
21
use Jitamin\Model\TaskModel;
22
23
/**
24
 * iCalendar Controller.
25
 */
26
class ICalendarController extends Controller
27
{
28
    /**
29
     * Get user iCalendar.
30
     */
31
    public function user()
32
    {
33
        $token = $this->request->getStringParam('token');
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Jitamin\Http\Cont...rs\ICalendarController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
34
        $user = $this->userModel->getByToken($token);
0 ignored issues
show
Documentation introduced by
The property userModel does not exist on object<Jitamin\Http\Cont...rs\ICalendarController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
35
36
        // Token verification
37
        if (empty($user)) {
38
            throw AccessForbiddenException::getInstance()->withoutLayout();
39
        }
40
41
        // Common filter
42
        $queryBuilder = new QueryBuilder();
43
        $queryBuilder
44
            ->withQuery($this->taskFinderModel->getICalQuery())
0 ignored issues
show
Documentation introduced by
The property taskFinderModel does not exist on object<Jitamin\Http\Cont...rs\ICalendarController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
45
            ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
46
            ->withFilter(new TaskAssigneeFilter($user['id']));
47
48
        // Calendar properties
49
        $calendar = new iCalendar('Jitamin');
50
        $calendar->setName($user['name'] ?: $user['username']);
51
        $calendar->setDescription($user['name'] ?: $user['username']);
52
        $calendar->setPublishedTTL('PT1H');
53
54
        $this->renderCalendar($queryBuilder, $calendar);
55
    }
56
57
    /**
58
     * Get project iCalendar.
59
     */
60
    public function project()
61
    {
62
        $token = $this->request->getStringParam('token');
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Jitamin\Http\Cont...rs\ICalendarController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
63
        $project = $this->projectModel->getByToken($token);
0 ignored issues
show
Documentation introduced by
The property projectModel does not exist on object<Jitamin\Http\Cont...rs\ICalendarController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
64
65
        // Token verification
66
        if (empty($project)) {
67
            throw AccessForbiddenException::getInstance()->withoutLayout();
68
        }
69
70
        // Common filter
71
        $queryBuilder = new QueryBuilder();
72
        $queryBuilder
73
            ->withQuery($this->taskFinderModel->getICalQuery())
0 ignored issues
show
Documentation introduced by
The property taskFinderModel does not exist on object<Jitamin\Http\Cont...rs\ICalendarController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
74
            ->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))
75
            ->withFilter(new TaskProjectFilter($project['id']));
76
77
        // Calendar properties
78
        $calendar = new iCalendar('Jitamin');
79
        $calendar->setName($project['name']);
80
        $calendar->setDescription($project['name']);
81
        $calendar->setPublishedTTL('PT1H');
82
83
        $this->renderCalendar($queryBuilder, $calendar);
84
    }
85
86
    /**
87
     * Common method to render iCal events.
88
     *
89
     * @param QueryBuilder $queryBuilder
90
     * @param iCalendar    $calendar
91
     */
92
    protected function renderCalendar(QueryBuilder $queryBuilder, iCalendar $calendar)
93
    {
94
        $start = $this->request->getStringParam('start', strtotime('-2 month'));
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Jitamin\Http\Cont...rs\ICalendarController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
95
        $end = $this->request->getStringParam('end', strtotime('+6 months'));
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Jitamin\Http\Cont...rs\ICalendarController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
96
97
        $this->helper->ical->addTaskDateDueEvents($queryBuilder, $calendar, $start, $end);
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Http\Cont...rs\ICalendarController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
98
99
        $formatter = new TaskICalFormatter($this->container);
100
        $this->response->ical($formatter->setCalendar($calendar)->format());
0 ignored issues
show
Documentation introduced by
The property response does not exist on object<Jitamin\Http\Cont...rs\ICalendarController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
101
    }
102
}
103