Completed
Pull Request — 1.5 (#747)
by Paweł
15:48
created

getSubscribingMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2019 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2019 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Serializer;
18
19
use JMS\Serializer\GraphNavigator;
20
use JMS\Serializer\Handler\SubscribingHandlerInterface;
21
use JMS\Serializer\JsonSerializationVisitor;
22
use SWP\Bundle\CoreBundle\Repository\ContentListItemRepositoryInterface;
23
use SWP\Component\Common\Criteria\Criteria;
24
25
final class ContentListItemsCountHandler implements SubscribingHandlerInterface
26
{
27
    /**
28
     * @var ContentListItemRepositoryInterface
29
     */
30
    private $contentListItemRepository;
31
32
    public function __construct(ContentListItemRepositoryInterface $contentListItemRepository)
33
    {
34
        $this->contentListItemRepository = $contentListItemRepository;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public static function getSubscribingMethods()
41
    {
42
        return [
43
            [
44
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
45
                'format' => 'json',
46
                'type' => 'SWP\Bundle\CoreBundle\Model\ContentListItemsCountInterface',
47
                'method' => 'serializeToJson',
48
            ],
49
        ];
50
    }
51
52
    public function serializeToJson(
53
        JsonSerializationVisitor $visitor,
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
        $data,
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
        $type,
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
        $context
57
    ) {
58
        $object = $context->getObject();
59
        $criteria = new Criteria();
60
        $criteria->set('contentList', $object);
61
62
        return $this->contentListItemRepository->getCountByCriteria($criteria, null);
0 ignored issues
show
Unused Code introduced by
The call to ContentListItemRepositor...e::getCountByCriteria() has too many arguments starting with null.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
63
    }
64
}
65