AdminPanelSession   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 45
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
getCurrentUrl() 0 1 ?
getContent() 0 1 ?
A getCurrentUrlKey() 0 4 1
A getSessionKeyForUrl() 0 9 2
A _findKeyForUrl() 0 13 2
1
<?php
2
3
namespace Magefix\Plugin;
4
5
/**
6
 * Class AdminPanelSession
7
 *
8
 *
9
 * @package Magefix\Plugin
10
 * @author  Carlo Tasca <[email protected]>
11
 */
12
trait AdminPanelSession
13
{
14
    abstract public function getCurrentUrl();
15
    abstract public function getContent();
16
17
    /**
18
     * @return string
19
     */
20
    public function getCurrentUrlKey()
21
    {
22
        return $this->_findKeyForUrl($this->getCurrentUrl());
23
    }
24
25
    /**
26
     * @param $url
27
     * @return mixed|string
28
     */
29
    public function getSessionKeyForUrl($url)
30
    {
31
        $content = $this->getContent();
32
        $matches = [];
33
        $url = rtrim($url, DS);
34
        preg_match("#{$url}/key/([a-z0-9]{1,})#", $content, $matches);
35
36
        return isset($matches[1]) ? $matches[1] : '';
37
    }
38
39
    /**
40
     * @param $url
41
     * @return string
42
     */
43
    private function _findKeyForUrl($url)
44
    {
45
        $key = '';
46
47
        $matches = [];
48
        preg_match('#key/[a-z0-9]{1,}#', $url, $matches);
49
50
        if (isset($matches[0])) {
51
            $key = str_replace('key/', '', $matches[0]);
52
        }
53
54
        return $key;
55
    }
56
}
57