Completed
Pull Request — master (#335)
by Simon
07:27 queued 03:11
created

ThumbnailManagerDummy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 8.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * (c) shopware AG <[email protected]>
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
require_once __DIR__ . '/../../../../../../../autoload.php';
9
10
use Shopware\Bundle\MediaBundle\OptimizerServiceInterface;
11
use Shopware\Components\Thumbnail\Manager;
12
use Shopware\Kernel;
13
use Shopware\Models\Media\Media;
14
15
class SwagConnectTestKernel
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
16
{
17
    public static function start()
0 ignored issues
show
Coding Style introduced by
start uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
18
    {
19
        $kernel = new Kernel(getenv('SHOPWARE_ENV') ?: 'testing', false);
20
        $kernel->boot();
21
22
        $container = $kernel->getContainer();
23
        $container->get('plugins')->Core()->ErrorHandler()->registerErrorHandler(E_ALL | E_STRICT);
24
25
        /** @var $repository \Shopware\Models\Shop\Repository */
26
        $repository = $container->get('models')->getRepository('Shopware\Models\Shop\Shop');
27
28
        $shop = $repository->getActiveDefault();
29
        $shop->registerResources();
30
31
        $_SERVER['HTTP_HOST'] = $shop->getHost();
32
33
        Shopware()->Loader()->registerNamespace('Tests\ShopwarePlugins\Connect', __DIR__ . '/Legacy/Shopware/Connect/');
34
        Shopware()->Container()->get('ConnectSDK');
35
36
        Shopware()->Container()->set('thumbnail_manager', new ThumbnailManagerDummy());
37
        Shopware()->Container()->set('shopware_media.cache_optimizer_service', new OptimizerServiceDummy());
38
        Shopware()->Container()->set('shopware_media.optimizer_service', new OptimizerServiceDummy());
39
    }
40
}
41
42
class ThumbnailManagerDummy extends Manager
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
43
{
44
    public function __construct()
45
    {
46
    }
47
48
    public function createMediaThumbnail(Media $media, $thumbnailSizes = [], $keepProportions = false)
49
    {
50
        return true;
51
    }
52
}
53
54
class OptimizerServiceDummy implements OptimizerServiceInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
55
{
56
    public function optimize($filepath)
57
    {
58
    }
59
60
    public function getOptimizers()
61
    {
62
    }
63
64
    public function getOptimizerByMimeType($mime)
65
    {
66
    }
67
}
68
69
SwagConnectTestKernel::start();
70