Issues (994)

src/User/access.php (5 issues)

1
<?php
2
3
namespace User;
4
5
class access
6
{
7
  private $config;
8
  /**
9
   * User instance.
10
   *
11
   * @var \User\user
12
   */
13
  private $user;
14
15
  public function __construct(\User\user $user)
16
  {
17
    $this->config = \Filemanager\file::file(__DIR__ . '/config/access/global.json', ['superuser' => '*']);
0 ignored issues
show
array('superuser' => '*') of type array<string,string> is incompatible with the type boolean expected by parameter $create of Filemanager\file::file(). ( Ignorable by Annotation )

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

17
    $this->config = \Filemanager\file::file(__DIR__ . '/config/access/global.json', /** @scrutinizer ignore-type */ ['superuser' => '*']);
Loading history...
18
    $this->user = $user;
19
  }
20
21
  public function check()
22
  {
23
  }
24
25
  /**
26
   * Get access lists.
27
   *
28
   * @return array
29
   */
30
  public function getAccess()
31
  {
32
    return \Filemanager\file::get($this->config, true);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Filemanager\file::get($this->config, true) also could return the type string which is incompatible with the documented return type array.
Loading history...
33
  }
34
35
  /**
36
   * Get root config.json.
37
   *
38
   * @return array
39
   */
40
  private function config()
41
  {
42
    return \Filemanager\file::get(ROOT . '/config.json', true);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Filemanager\file:.... '/config.json', true) also could return the type string which is incompatible with the documented return type array.
Loading history...
43
  }
44
45
  private $managedAccess;
46
47
  /**
48
   * Get list of managed access, that requires spesific user roles.
49
   *
50
   * @return array
51
   */
52
  public function get_managed_access()
53
  {
54
    if (!$this->managedAccess) {
55
      $app = $this->config();
56
      if (isset($app['app'])) {
57
        $app = $app['app'];
58
      } else {
59
        throw new \MVC\Exception('Config failed, no `app` property', 1);
60
      }
61
      $read = \Filemanager\scan::scandir(ROOT . '/' . $app['views']);
62
      $flist = [];
63
      foreach ($read as $files) {
64
        $flist[] = \MVC\helper::get_url_path($files['path']);
65
      }
66
      $flist = array_map(function ($path) use ($app) {
67
        //strip extensions
68
        $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $path);
69
        /**
70
         * Group ignore patterns.
71
         */
72
        $patterns = [
73
          // ignore static file and form controller
74
          "\-f.php$|\.(js|css|json|txt|log|htaccess|gitignore)$",
75
          // ignore not special access
76
          "\/(login|logout|signup|test)\.php$",
77
          // ignore unmanaged zones
78
          "\/(fb|css|chat|comments|curl|snippets|vpngate|blog|server|php|proxy|im3|telkomsel|byu|axis|google|auth|agc|alquran|img|tools|coupon|login|test)\/",
79
          // ignore public access
80
          "^\/{$app['views']}\/(index|dashboard|profile|php-socket|user)\.php$",
81
        ];
82
83
        $ignore = preg_match_all('/' . implode('|', $patterns) . '/s', $path);
84
        if (!$ignore) {
85
          return $withoutExt;
86
        }
87
88
        return null;
89
      }, $flist);
90
91
      $this->managedAccess = array_values(array_filter($flist));
92
    }
93
94
    return $this->managedAccess;
95
  }
96
97
  /**
98
   * Save new configuration.
99
   *
100
   * @return bool
101
   */
102
  public function save(array $newData)
103
  {
104
    $config = $this->getAccess();
0 ignored issues
show
The assignment to $config is dead and can be removed.
Loading history...
105
    //$merge = array_replace($config, $newData);
106
107
    return !empty(trim(\Filemanager\file::file($this->config, $newData, true)));
0 ignored issues
show
$newData of type array is incompatible with the type boolean expected by parameter $create of Filemanager\file::file(). ( Ignorable by Annotation )

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

107
    return !empty(trim(\Filemanager\file::file($this->config, /** @scrutinizer ignore-type */ $newData, true)));
Loading history...
108
  }
109
}
110