TaskFileModel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 93
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 4 1
A getForeignKey() 0 4 1
A getPathPrefix() 0 4 1
A getProjectId() 0 8 2
A uploadScreenshot() 0 6 1
A fireCreationEvent() 0 4 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\Model;
13
14
/**
15
 * Task File Model.
16
 */
17
class TaskFileModel extends FileModel
18
{
19
    /**
20
     * Table name.
21
     *
22
     * @var string
23
     */
24
    const TABLE = 'task_has_files';
25
26
    /**
27
     * Events.
28
     *
29
     * @var string
30
     */
31
    const EVENT_CREATE = 'task.file.create';
32
33
    /**
34
     * Get the table.
35
     *
36
     * @abstract
37
     *
38
     * @return string
39
     */
40
    protected function getTable()
41
    {
42
        return self::TABLE;
43
    }
44
45
    /**
46
     * Define the foreign key.
47
     *
48
     * @abstract
49
     *
50
     * @return string
51
     */
52
    protected function getForeignKey()
53
    {
54
        return 'task_id';
55
    }
56
57
    /**
58
     * Define the path prefix.
59
     *
60
     * @abstract
61
     *
62
     * @return string
63
     */
64
    protected function getPathPrefix()
65
    {
66
        return 'tasks';
67
    }
68
69
    /**
70
     * Get projectId from fileId.
71
     *
72
     * @param int $file_id
73
     *
74
     * @return int
75
     */
76
    public function getProjectId($file_id)
77
    {
78
        return $this->db
0 ignored issues
show
Documentation introduced by
The property db does not exist on object<Jitamin\Model\TaskFileModel>. 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...
79
            ->table(self::TABLE)
80
            ->eq(self::TABLE.'.id', $file_id)
81
            ->join(TaskModel::TABLE, 'id', 'task_id')
82
            ->findOneColumn(TaskModel::TABLE.'.project_id') ?: 0;
83
    }
84
85
    /**
86
     * Handle screenshot upload.
87
     *
88
     * @param int    $task_id Task id
89
     * @param string $blob    Base64 encoded image
90
     *
91
     * @return bool|int
92
     */
93
    public function uploadScreenshot($task_id, $blob)
94
    {
95
        $original_filename = l('Screenshot taken %s', $this->helper->dt->datetime(time())).'.png';
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Model\TaskFileModel>. 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
        return $this->uploadContent($task_id, $original_filename, $blob);
98
    }
99
100
    /**
101
     * Fire file creation event.
102
     *
103
     * @param int $file_id
104
     */
105
    protected function fireCreationEvent($file_id)
106
    {
107
        $this->queueManager->push($this->taskFileEventJob->withParams($file_id, self::EVENT_CREATE));
0 ignored issues
show
Documentation introduced by
The property queueManager does not exist on object<Jitamin\Model\TaskFileModel>. 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 taskFileEventJob does not exist on object<Jitamin\Model\TaskFileModel>. 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...
108
    }
109
}
110