CompressorDecorator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace DneCustomJsCss\Services;
4
5
use Doctrine\DBAL\Connection;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Connection 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...
6
use Shopware\Components\Theme\Compressor\CompressorInterface;
0 ignored issues
show
Bug introduced by
The type Shopware\Components\Them...sor\CompressorInterface 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...
7
use Shopware\Models\Shop\Shop;
0 ignored issues
show
Bug introduced by
The type Shopware\Models\Shop\Shop 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...
8
9
class CompressorDecorator implements CompressorInterface
10
{
11
    /**
12
     * @var CompressorInterface
13
     */
14
    private $compressor;
15
16
    /**
17
     * @var Connection
18
     */
19
    private $connection;
20
21
    /**
22
     * @var Shop
23
     */
24
    private $shop;
25
26
    /**
27
     * CompressorDecorator constructor.
28
     *
29
     * @param CompressorInterface $compressor
30
     * @param Connection          $connection
31
     */
32
    public function __construct(CompressorInterface $compressor, Connection $connection)
33
    {
34
        $this->compressor = $compressor;
35
        $this->connection = $connection;
36
    }
37
38
    /**
39
     * @param Shop $shop
40
     */
41
    public function setShop(Shop $shop)
42
    {
43
        $this->shop = $shop;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function compress($content)
50
    {
51
        $qb = $this->connection->createQueryBuilder();
52
        $qb->select(
53
                ['js']
54
            )
55
            ->from('dne_custom_js_css')
56
            ->where('active = 1')
57
            ->andWhere('FIND_IN_SET(:shopId, shopIds)')
58
            ->setParameter('shopId', $this->shop->getId())
59
            ->orderBy('name', 'asc');
60
61
        $scripts = $qb->execute()->fetchAll(\PDO::FETCH_COLUMN);
62
63
        foreach ($scripts as $script) {
64
            $content .= $script . "\n";
65
        }
66
67
        return $this->compressor->compress($content);
68
    }
69
}
70