Skip to content

Commit

Permalink
Merge branch 'TomasVotruba-tv-phpstan'
Browse files Browse the repository at this point in the history
  • Loading branch information
donjajo committed Feb 28, 2022
2 parents 29a4ca8 + 41cf84e commit 0890b34
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
},
"require-dev": {
"symplify/easy-coding-standard": "dev-main",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.4"
},
"scripts": {
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi"
"fix-cs": "vendor/bin/ecs check --fix --ansi",
"phpstan": "vendor/bin/phpstan --ansi"
}
}
12 changes: 6 additions & 6 deletions helpers/dataTypes.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
<?php
/**
* Converts objects to array
*
* @param object $obj object(s)
*
* @return array
*
* @param mixed $obj object(s)
*
* @return array|mixed
*/
function obj_to_array( $obj ) {
// Not an array or object? Return back what was given
if( !is_array( $obj ) && !is_object( $obj ) )
if( !is_array( $obj ) && !is_object( $obj ) )
return $obj;

$arr = (array) $obj;
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 4

paths:
- src
- helpers
22 changes: 8 additions & 14 deletions src/JSONDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,14 @@ private function check_file()
// Check if its arrays of jSON
if (! is_array($content) && is_object($content)) {
throw new \Exception('An array of json is required: Json data enclosed with []');
return false;
}
// An invalid jSON file
elseif (! is_array($content) && ! is_object($content)) {
throw new \Exception('json is invalid');
return false;
} else {
$this->content = $content;
return true;
}
$this->content = $content;
return true;
}

public function select($args = '*')
Expand Down Expand Up @@ -171,7 +170,8 @@ public function where(array $columns, $merge = 'OR')
/**
* Implements regex search on where statement.
*
* @param int $preg_match_flags See https://www.php.net/manual/en/function.preg-match.php
* @param string $pattern Regex pattern
* @param int $preg_match_flags Flags for preg_grep(). See - https://www.php.net/manual/en/function.preg-match.php
*/
public static function regex(string $pattern, int $preg_match_flags = 0): object
{
Expand Down Expand Up @@ -201,7 +201,6 @@ public function update(array $columns)
* @param string $file json filename without extension
* @param array $values Array of columns as keys and values
*
* @return array $last_indexes Array of last index inserted
*/
public function insert($file, array $values)
{
Expand Down Expand Up @@ -232,10 +231,7 @@ public function insert($file, array $values)
}

$this->content[] = $values;
// $this->last_indexes = [ ( count( $this->content ) - 1 ) ];
$this->commit();

// return $this->last_indexes;
}

public function commit()
Expand Down Expand Up @@ -327,21 +323,21 @@ private function _update()
if (! array_diff_key($this->update, $content)) {
$this->content[$i] = (object) array_merge($content, $this->update);
} else {
throw new Exception('Update method has an off key');
throw new \Exception('Update method has an off key');
}
} else {
continue;
}
}
} elseif (! empty($this->where) && empty($this->last_indexes)) {
null;
return;
} else {
foreach ($this->content as $i => $v) {
$content = (array) $this->content[$i];
if (! array_diff_key($this->update, $content)) {
$this->content[$i] = (object) array_merge($content, $this->update);
} else {
throw new Exception('Update method has an off key ');
throw new \Exception('Update method has an off key ');
}
}
}
Expand Down Expand Up @@ -381,8 +377,6 @@ public function trigger()

/**
* Flushes indexes they won't be reused on next action
*
* @return object $this
*/
private function flush_indexes($flush_where = false)
{
Expand Down

0 comments on commit 0890b34

Please sign in to comment.