BlogArticle::_getCommentCountFormat()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace App\Model\Entity;
3
4
use App\Model\Behavior\AppTranslateTrait;
5
use Cake\Core\Configure;
6
use Cake\I18n\Number;
7
use Cake\ORM\Behavior\Translate\TranslateTrait;
8
use Cake\ORM\Entity;
9
use HTMLPurifier;
10
use HTMLPurifier_Config;
11
12
class BlogArticle extends Entity
13
{
14
15
    use AppTranslateTrait;
16
    use TranslateTrait;
17
18
    /**
19
     * Fields that can be mass assigned using newEntity() or patchEntity().
20
     *
21
     * @var array
22
     */
23
    protected $_accessible = [
24
        '*' => true,
25
        'id' => false,
26
    ];
27
28
    /**
29
     * Purify the content for display the article.
30
     *
31
     * @param string $content The content to be purified.
32
     *
33
     * @return string
34
     */
35
    protected function _getContent($content)
36
    {
37
        $config = HTMLPurifier_Config::createDefault();
38
        $config->loadArray(Configure::read('HtmlPurifier.Blog.article'));
39
40
        $HTMLPurifier = new HTMLPurifier($config);
41
42
        return $HTMLPurifier->purify($content);
43
    }
44
45
    /**
46
     * Purify the content for display the article on category/archives/index blog page.
47
     *
48
     * @return string
49
     */
50
    protected function _getContentEmpty()
51
    {
52
        $config = HTMLPurifier_Config::createDefault();
53
        $config->loadArray(Configure::read('HtmlPurifier.Blog.article_empty'));
54
55
        $HTMLPurifier = new HTMLPurifier($config);
56
57
        return $HTMLPurifier->purify($this->content);
0 ignored issues
show
Documentation introduced by
The property content does not exist on object<App\Model\Entity\BlogArticle>. 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...
58
    }
59
60
    /**
61
     * Purify the content for display the article in meta tags.
62
     *
63
     * @return string
64
     */
65
    protected function _getContentMeta()
66
    {
67
        $config = HTMLPurifier_Config::createDefault();
68
        $config->loadArray(Configure::read('HtmlPurifier.Blog.article_meta'));
69
70
        $HTMLPurifier = new HTMLPurifier($config);
71
72
        return $HTMLPurifier->purify($this->content);
0 ignored issues
show
Documentation introduced by
The property content does not exist on object<App\Model\Entity\BlogArticle>. 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...
73
    }
74
75
    /**
76
     * Get the last page of an article.
77
     *
78
     * @return int
79
     */
80
    protected function _getLastPage()
81
    {
82
        $page = ceil($this->comment_count / Configure::read('Blog.comment_per_page'));
0 ignored issues
show
Documentation introduced by
The property comment_count does not exist on object<App\Model\Entity\BlogArticle>. 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...
83
84
        return ($page) ? $page : 1;
85
    }
86
87
    /**
88
     * Get the number of comments formatted.
89
     *
90
     * @return string
91
     */
92
    protected function _getCommentCountFormat()
93
    {
94
        return Number::format($this->comment_count);
0 ignored issues
show
Documentation introduced by
The property comment_count does not exist on object<App\Model\Entity\BlogArticle>. 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
    }
96
97
    /**
98
     * Get the number of likes formatted.
99
     *
100
     * @return string
101
     */
102
    protected function _getLikeCountFormat()
103
    {
104
        return Number::format($this->like_count);
0 ignored issues
show
Documentation introduced by
The property like_count does not exist on object<App\Model\Entity\BlogArticle>. 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...
105
    }
106
}
107