Completed
Push — master ( 084bf7...f394ee )
by Korotkov
01:16
created

CommonHelper::redirectToSelf()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace App\Http\Supports;
4
5
trait CommonHelper
6
{
7
8
    /**
9
     * @param $slug
10
     *
11
     * @return string
12
     */
13
    protected function getIdFromSlug(string $slug) :string
14
    {
15
      $slug = strip_tags($slug);
16
17
      return (strpos($slug, '_') !== false) ? strstr($slug, '_', true) : $slug;
18
    }
19
20
    /**
21
     * @param string $uri
22
     *
23
     * @return mixed
24
     */
25
    protected function redirectToSelf(string $uri)
26
    {
27
      $page = $this->validation()->sanitize($this->post('page'))->required()->run();
0 ignored issues
show
Bug introduced by
It seems like validation() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
28
29
      if ($this->validation()->access($page)) {
0 ignored issues
show
Bug introduced by
It seems like validation() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
30
        return $this->redirect($uri . '/page/' . $page[0]);
0 ignored issues
show
Bug introduced by
The method redirect() does not exist on App\Http\Supports\CommonHelper. Did you maybe mean redirectToSelf()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
31
      }
32
33
      return $this->redirect($uri);
0 ignored issues
show
Bug introduced by
The method redirect() does not exist on App\Http\Supports\CommonHelper. Did you maybe mean redirectToSelf()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
34
    }
35
36
    /**
37
     * @param $array
38
     * @param $arrayKey
39
     *
40
     * @return int|string
41
     */
42
    public function searchArrayKey($array, $arrayKey)
43
    {
44
        foreach ($array as $key => $value) {
45
            if (stristr($key, $arrayKey) !== false) {
46
                return $key;
47
            }
48
        }
49
    }
50
51
    /**
52
     * @param $value
53
     *
54
     * @return string
55
     */
56
    public function dateFormat($value)
57
    {
58
        $date  = \DateTime::createFromFormat('d.m.Y H:i', $value);
59
        $value = $date->format('Y-m-d H:i');
60
61
        return $value;
62
    }
63
64
    /**
65
     * @param $value
66
     *
67
     * @return int
68
     */
69
    public function checkbox($value)
70
    {
71
        return ($value) ? '1' : '0';
72
    }
73
}