CategoryHelper::forSelect()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Category\View\Helper;
6
7
use Category\Service\CategoryService;
8
use Zend\View\Helper\AbstractHelper;
9
10
class CategoryHelper extends AbstractHelper
11
{
12
    /** @var CategoryService */
13
    private $categoryService;
14
15
    /** @var array */
16
    private $homepageCategories;
17
18
    /**
19
     * CategoryHelper constructor.
20
     *
21
     * @param CategoryService $categoryService
22
     */
23
    public function __construct(CategoryService $categoryService)
24
    {
25
        $this->categoryService = $categoryService;
26
    }
27
28
    /** @return $this */
29
    public function __invoke()
30
    {
31
        return $this;
32
    }
33
34
    /** @return \Zend\Db\ResultSet\ResultSet */
35
    public function forSelect()
36
    {
37
        return $this->categoryService->getAll();
38
    }
39
40
    /**
41
     * We need to return X categories with Y posts in every category sorted by
42
     * magic for homepage. magic = most viewed, most comments, most appropriate
43
     * for the user etc. etc. for now return just latest.
44
     */
45
    public function forHomepage()
46
    {
47
        if (!$this->homepageCategories) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->homepageCategories of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
48
            $this->homepageCategories = $this->categoryService->getCategoriesWithPosts(true);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->categoryService->...tegoriesWithPosts(true) of type * is incompatible with the declared type array of property $homepageCategories.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
        }
50
51
        return $this->homepageCategories;
52
    }
53
}
54