Passed
Pull Request — master (#13)
by
unknown
06:11
created

BannerAjaxLoadControllerPlugin::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace IntegerNet\SessionUnblocker\Plugin;
5
6
use Magento\Framework\Session\Generic as GenericSession;
7
use Magento\Framework\Session\SessionManagerInterface;
8
9
/**
10
 * We are writing this plugin to make sure sessions are all loaded
11
 * Magento\Banner\Controller\Ajax\Load
12
 *
13
 * Right after initiating all the needed Sessions we close the session,
14
 * since we're only reading from the session when requesting banners.
15
 */
16
class BannerAjaxLoadControllerPlugin
17
{
18
    /**
19
     * @param GenericSession $genericSession
20
     * @param SessionManagerInterface[] $additionalSessions
21
     *
22
     * Disabling 3 PHPCS rules because:
23
     * 1 - We are well aware that we normally shouldn't call Sessions without
24
     *     proxy, but in this case, we actually want the sessions to be
25
     *     initiated directly.
26
     * 2 - Also, we don't actually use the Sessions
27
     * 3 - Lastly, we normally should not execute operations in a constructor
28
     *
29
     * phpcs:disable MEQP2.Classes.MutableObjects.MutableObjects
30
     * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.Found
31
     * phpcs:disable MEQP2.Classes.ConstructorOperations.CustomOperationsFound
32
     */
33
    public function __construct(
34
        GenericSession $genericSession,
35
        array $additionalSessions = []
0 ignored issues
show
Unused Code introduced by
The parameter $additionalSessions is not used and could be removed. ( Ignorable by Annotation )

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

35
        /** @scrutinizer ignore-unused */ array $additionalSessions = []

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

Loading history...
36
    ) {
37
        /**
38
         * This is earliest moment where we can close the session,
39
         * after we initialised all sessions we think will be needed
40
         *
41
         * Should there ever be an additional Session-type that's needed,
42
         * nothing breaks, but the new session-type will open a new session
43
         * and therefore block other requests
44
         */
45
        $genericSession->writeClose();
46
    }
47
48
    //phpcs:ignore MEQP2.Classes.PublicNonInterfaceMethods.PublicMethodFound
49
    public function beforeExecute()
50
    {
51
    }
52
}
53