ProjectActivityHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 36.05 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 31
loc 86
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A searchEvents() 0 18 2
A getProjectEvents() 11 11 1
A getProjectsEvents() 11 11 1
A getTaskEvents() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

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
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\Helper;
13
14
use Jitamin\Filter\ProjectActivityProjectIdFilter;
15
use Jitamin\Filter\ProjectActivityProjectIdsFilter;
16
use Jitamin\Filter\ProjectActivityTaskIdFilter;
17
use Jitamin\Formatter\ProjectActivityEventFormatter;
18
use Jitamin\Foundation\Base;
19
use Jitamin\Model\ProjectActivityModel;
20
21
/**
22
 * Project Activity Helper.
23
 */
24
class ProjectActivityHelper extends Base
25
{
26
    /**
27
     * Search events.
28
     *
29
     * @param string $search
30
     * @param int    $limit
31
     *
32
     * @return array
33
     */
34
    public function searchEvents($search, $limit = 50)
35
    {
36
        $projects = $this->projectUserRoleModel->getActiveProjectsByUser($this->userSession->getId());
0 ignored issues
show
Documentation introduced by
The property projectUserRoleModel does not exist on object<Jitamin\Helper\ProjectActivityHelper>. 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...
Documentation introduced by
The property userSession does not exist on object<Jitamin\Helper\ProjectActivityHelper>. 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...
37
        $events = [];
38
39
        if ($search !== '') {
40
            $queryBuilder = $this->projectActivityLexer->build($search);
0 ignored issues
show
Documentation introduced by
The property projectActivityLexer does not exist on object<Jitamin\Helper\ProjectActivityHelper>. 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...
41
            $queryBuilder
42
                ->withFilter(new ProjectActivityProjectIdsFilter(array_keys($projects)))
43
                ->getQuery()
44
                ->desc(ProjectActivityModel::TABLE.'.id')
45
                ->limit($limit);
46
47
            $events = $queryBuilder->format(new ProjectActivityEventFormatter($this->container));
48
        }
49
50
        return $events;
51
    }
52
53
    /**
54
     * Get project activity events.
55
     *
56
     * @param int $project_id
57
     * @param int $limit
58
     *
59
     * @return array
60
     */
61 View Code Duplication
    public function getProjectEvents($project_id, $limit = 50)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        $queryBuilder = $this->projectActivityQuery
0 ignored issues
show
Documentation introduced by
The property projectActivityQuery does not exist on object<Jitamin\Helper\ProjectActivityHelper>. 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
            ->withFilter(new ProjectActivityProjectIdFilter($project_id));
65
66
        $queryBuilder->getQuery()
67
            ->desc(ProjectActivityModel::TABLE.'.id')
68
            ->limit($limit);
69
70
        return $queryBuilder->format(new ProjectActivityEventFormatter($this->container));
71
    }
72
73
    /**
74
     * Get projects activity events.
75
     *
76
     * @param int[] $project_ids
77
     * @param int   $limit
78
     *
79
     * @return array
80
     */
81 View Code Duplication
    public function getProjectsEvents(array $project_ids, $limit = 50)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
    {
83
        $queryBuilder = $this->projectActivityQuery
0 ignored issues
show
Documentation introduced by
The property projectActivityQuery does not exist on object<Jitamin\Helper\ProjectActivityHelper>. 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...
84
            ->withFilter(new ProjectActivityProjectIdsFilter($project_ids));
85
86
        $queryBuilder->getQuery()
87
            ->desc(ProjectActivityModel::TABLE.'.id')
88
            ->limit($limit);
89
90
        return $queryBuilder->format(new ProjectActivityEventFormatter($this->container));
91
    }
92
93
    /**
94
     * Get task activity events.
95
     *
96
     * @param int $task_id
97
     *
98
     * @return array
99
     */
100 View Code Duplication
    public function getTaskEvents($task_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
    {
102
        $queryBuilder = $this->projectActivityQuery
0 ignored issues
show
Documentation introduced by
The property projectActivityQuery does not exist on object<Jitamin\Helper\ProjectActivityHelper>. 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...
103
            ->withFilter(new ProjectActivityTaskIdFilter($task_id));
104
105
        $queryBuilder->getQuery()->desc(ProjectActivityModel::TABLE.'.id');
106
107
        return $queryBuilder->format(new ProjectActivityEventFormatter($this->container));
108
    }
109
}
110