Passed
Push — main ( ecb236...bcdbab )
by Alireza
05:51 queued 04:21
created

handller::CheckParam()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 10
rs 9.9666
c 0
b 0
f 0
cc 4
nc 2
nop 1
1
<?php
2
3
  //define namespace
4
  namespace BPT;
5
  
6
  //use class
7
  use BPT\database;
0 ignored issues
show
Bug introduced by
The type BPT\database was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
  
9
  /**
10
   * 
11
   */
12
  class handller extends database
13
  {
14
      
15
      /**
16
       * 
17
       */
18
      public function __construct(array $settings)
19
      {
20
        if(in_array($settings['type'],self::TYPES)){
21
              if($settings['type'] === 'Mysqli'){
22
                  if(self::CheckParam($settings)){
23
                 $db = new Mysqlidb([
0 ignored issues
show
Bug introduced by
The type BPT\Mysqlidb was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
                'host' => $this->host,
25
                'username' => $this->username,
26
                'password' => $this->password,
27
                'db' => $this->dbname,
28
                'charset' => $this->charset
29
                ]);
30
                if($db){
0 ignored issues
show
introduced by
$db is of type BPT\Mysqlidb, thus it always evaluated to true.
Loading history...
31
                  $this->connect = $db;
0 ignored issues
show
Bug Best Practice introduced by
The property connect does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32
               } else {
33
                  throw new \exception('a problem to connecting');
34
                 }
35
               } else {
36
                  throw new \exception('required parameters not found');
37
               }
38
             }
39
              if($settings['type'] === 'Json' and isset($settings['dbname'])){
40
                $this->type = $settings['type'];
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
41
                $this->dbname = $settings['dbname'];
0 ignored issues
show
Bug Best Practice introduced by
The property dbname does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
42
                parent::Json_init();
43
              } else {
44
                throw new \exception('parameter dbanme not found');
45
             }
46
          } else {
47
              throw new \exception('parameter type not found');
48
          }
49
      }
50
      
51
      private static function CheckParam(array $array){
52
         if(isset($array['username']) && isset($array['dbname']) && isset($array['password'])){
53
            $this->host = $array['host'] ?? 'localhost';
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using $this inside a static method is generally not recommended and can lead to errors in newer PHP versions.
Loading history...
Bug Best Practice introduced by
The property host does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
54
            $this->username = $array['username'];
0 ignored issues
show
Bug Best Practice introduced by
The property username does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
55
            $this->dbname = $array['dbname'];
0 ignored issues
show
Bug Best Practice introduced by
The property dbname does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
56
            $this->password = $array['password'];
0 ignored issues
show
Bug Best Practice introduced by
The property password does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
57
            $this->charset = $array['charset'] ?? 'utf8mb4';
0 ignored issues
show
Bug Best Practice introduced by
The property charset does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
58
             return true;
59
         } else {
60
             return false;
61
         }
62
      }
63
  }