Completed
Push — master ( 05bb5a...5289b8 )
by Rafał
34:32 queued 04:15
created

ContentListItemsCountHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 27.5 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 11
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A serializeToJson() 0 12 1
A getSubscribingMethods() 11 11 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
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 View Code Duplication
    public static function getSubscribingMethods()
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...
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