AdminPanelSession::getCurrentUrlKey()   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 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
nc 1
cc 1
eloc 2
nop 0
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