Passed
Push — master ( 305978...d3671c )
by Aimeos
16:54
created

LatestOrdersWidget   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A renderWidgetContent() 0 5 1
A getOptions() 0 3 1
A setRequest() 0 3 1
1
<?php
2
3
/**
4
 * @license GPLv3, http://www.gnu.org/copyleft/gpl.html
5
 * @copyright Aimeos (aimeos.org), 2020
6
 * @package TYPO3
7
 */
8
9
10
namespace Aimeos\Aimeos\Widgets;
11
12
13
/**
14
 * Renders a widgent of the latest orders
15
 * @package TYPO3
16
 */
17
class LatestOrdersWidget implements \TYPO3\CMS\Dashboard\Widgets\WidgetInterface
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Dashboard\Widgets\WidgetInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
{
19
    private ServerRequestInterface $request;
0 ignored issues
show
Bug introduced by
The type Aimeos\Aimeos\Widgets\ServerRequestInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
21
22
    public function __construct(
23
        private readonly WidgetConfigurationInterface $configuration,
0 ignored issues
show
Bug introduced by
The type Aimeos\Aimeos\Widgets\WidgetConfigurationInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
        private readonly Cache $cache,
0 ignored issues
show
Bug introduced by
The type Aimeos\Aimeos\Widgets\Cache was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
        private readonly BackendViewFactory $backendViewFactory,
0 ignored issues
show
Bug introduced by
The type Aimeos\Aimeos\Widgets\BackendViewFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
        private readonly ?ButtonProviderInterface $buttonProvider = null,
0 ignored issues
show
Bug introduced by
The type Aimeos\Aimeos\Widgets\ButtonProviderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
        private readonly array $options = []
28
    ) {
29
    }
30
31
32
    public function getOptions(): array
33
    {
34
        return $this->options;
35
    }
36
37
38
    public function setRequest(ServerRequestInterface $request): void
39
    {
40
        $this->request = $request;
41
    }
42
43
44
    /**
45
     * Renders the content for the widget
46
     *
47
     * @return string HTML code
48
     */
49
    public function renderWidgetContent(): string
50
    {
51
        $view = $this->backendViewFactory->create($this->request);
0 ignored issues
show
Unused Code introduced by
The assignment to $view is dead and can be removed.
Loading history...
52
        return $this->view->assign('items', $this->getOrderItems())
53
            ->render('Widgets/LatestOrdersWidget');
54
    }
55
56
57
    /**
58
     * Returns the latest order items
59
     *
60
     * @return array Associative list of order IDs as keys and order items as values
61
     */
62
    protected function getOrderItems() : array
63
    {
64
        $config = \Aimeos\Aimeos\Base::config();
65
        $context = \Aimeos\Aimeos\Base::context($config);
66
67
        $manager = \Aimeos\MShop::create($context, 'order');
68
        $filter = $manager->filter()->sort('-order.id')->slice(0, 20);
0 ignored issues
show
Bug introduced by
The method slice() does not exist on Aimeos\Base\Criteria\Expression\Sort\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        $filter = $manager->filter()->sort('-order.id')->/** @scrutinizer ignore-call */ slice(0, 20);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The call to Aimeos\Base\Criteria\Iface::sort() has too few arguments starting with name. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        $filter = $manager->filter()->/** @scrutinizer ignore-call */ sort('-order.id')->slice(0, 20);

This check compares calls to functions or methods with their respective definitions. If the call has less 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. Please note the @ignore annotation hint above.

Loading history...
69
70
        return $manager->search($filter, ['order/base/address'])->toArray();
71
    }
72
}