Passed
Push — main ( 2690c9...b16527 )
by Alireza
02:55 queued 01:27
created

Handller::CheckParam()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 10
rs 9.9666
cc 4
nc 2
nop 1
1
<?php
2
3
  //define namespace
4
  namespace BPT\Database;
5
  
6
  //use class
7
  use BPT\Database\Database;
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\Database\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\Database\Mysqlidb, thus it always evaluated to true.
Loading history...
31
                  $this->connect = $db;
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'];
41
                $this->dbname = $settings['dbname'];
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...
Documentation Bug introduced by
It seems like $array['host'] ?? 'localhost' can also be of type string. However, the property $host is declared as type BPT\Database\host. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
54
            $this->username = $array['username'];
55
            $this->dbname = $array['dbname'];
56
            $this->password = $array['password'];
57
            $this->charset = $array['charset'] ?? 'utf8mb4';
0 ignored issues
show
Documentation Bug introduced by
It seems like $array['charset'] ?? 'utf8mb4' can also be of type string. However, the property $charset is declared as type BPT\Database\charset. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
58
             return true;
59
         } else {
60
             return false;
61
         }
62
      }
63
  }