Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ permissions:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}

- name: Validate composer.json and composer.lock
run: composer validate --strict

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require-dev": {
"symfony/console": "^4.4",
"phpunit/phpunit": "^8.5",
"phpunit/phpunit": "^8.5 || ^9.0 || ^10.0",
"phpstan/phpstan": "^1.8",
"squizlabs/php_codesniffer": "^3.5",
"friendsofphp/php-cs-fixer": "^2.16 || ^3.0",
Expand Down
1 change: 0 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<!-- Don't require tabs for indentation -->
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent" />
<exclude name="Squiz.Strings.DoubleQuoteUsage.NotRequired" />
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore" />

<properties>
<property name="minimumWarningSeverity" value="0" />
Expand Down
24 changes: 17 additions & 7 deletions src/Data/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DataObject extends RecursiveArrayIterator implements DataInterface
/**
* Constructor
*
* @param array|object $obj The object to use
* @param array|object $data The object to use
*/
public function __construct($data)
{
Expand All @@ -53,6 +53,10 @@ public function __construct($data)

/**
* Init data object
*
* @param string $path
*
* @return DataPath
*/
public function pathInit(string $path): DataPath
{
Expand Down Expand Up @@ -93,7 +97,7 @@ public function cache(string $path, $value): void
*
* @return mixed
*/
public function get(string $path)
public function get(?string $path = null)
{
if ($this->cache->isCached($path)) {
return $this->cache->get($path);
Expand Down Expand Up @@ -174,10 +178,6 @@ public function set(string $path, $value): void
// Returned DataPath object
$path_ = $this->pathInit($path);

if (!$path_) {
return;
}

// Add given value to the cache
$this->cache($path, $value);

Expand Down Expand Up @@ -312,6 +312,16 @@ public function key(): string
*/
public function has(string $path): bool
{
return in_array($path, $this->paths, true);
return array_key_exists($path, $this->paths);
}

/**
* @return DataObject|null
*/
#[\ReturnTypeWillChange]
public function getChildren()
{
/** @var DataObject|null */
return parent::getChildren();
}
}
5 changes: 2 additions & 3 deletions src/Data/DataPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ public function __construct(string $path)
}

/**
* Inıt path
* Init path
*
* @param string $path
* @param DataInterface $data
* @param string $path
*
* @return DataPath
*/
Expand Down
16 changes: 9 additions & 7 deletions src/Data/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function setRules(array $rules): void
* Checks whether the value which is in the desired path
* and added to the control list is valid or not
*
* @param string $path requested path
* @param string $path requested path
*
* @return bool
*/
Expand All @@ -167,8 +167,10 @@ public function isValid(string $path = ''): bool
/**
* Adds new validation error status to the validationStatus array
*
* @param string $path requested path
* @param bool $status validation status
* @param string $path requested path
* @param mixed $value Data value
* @param string $pattern Validation pattern
* @param bool $required Is value required
*
* @return bool
*/
Expand All @@ -183,10 +185,10 @@ public function setValidationStatus(string $path, $value, string $pattern, bool
/**
* Sets the status to the all parent paths.
*
* @param string $path Data path
* @param mixed $value Data value
* @param string $pattern Validation pattern
* @param bool $status Is value required
* @param string $path Data path
* @param mixed $value Data value
* @param string $pattern Validation pattern
* @param bool $required Is value required
*/
public function addValidationStatus(string $path, $value, string $pattern, bool $required): void
{
Expand Down
5 changes: 3 additions & 2 deletions src/Helpers/DataParsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public function findPaths(string $path, array $data, ?Closure $closure = null):
$paths = [];

foreach ($data as $key => $val) {
if (substr_count($path, "*") > 0) {
$path_ = substr_replace($path, $key, strpos($path, "*"), 1);
$pos = strpos($path, "*");
if ($pos !== false) {
$path_ = substr_replace($path, (string)$key, $pos, 1);

if ($closure) {
$val = $closure($path_, $val);
Expand Down
8 changes: 4 additions & 4 deletions src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Middleware
*
* @var array
*/
private array $_options = [];
private array $options = [];

/**
* __construct function
Expand All @@ -39,7 +39,7 @@ class Middleware
*/
public function __construct(array $options = [])
{
$this->_options = $options;
$this->options = $options;
}

/**
Expand All @@ -52,7 +52,7 @@ public function __construct(array $options = [])
*/
public function set(string $name, $value): void
{
$this->_options[$name] = $value;
$this->options[$name] = $value;
}

/**
Expand All @@ -64,7 +64,7 @@ public function set(string $name, $value): void
*/
public function get(string $name)
{
return $this->_options[$name] ?? null;
return $this->options[$name] ?? null;
}

/**
Expand Down
45 changes: 23 additions & 22 deletions src/StringObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,51 +36,51 @@ class StringObjects
*
* @var DataObject
*/
private DataObject $_obj;
private DataObject $obj;

/**
* Validation object
*
* @var Validation
*/
private Validation $_validation;
private Validation $validation;

/**
* Middleware object
*
* @var Middleware
*/
private Middleware $_middleware;
private Middleware $middleware;

/**
* Filters object
*
* @var DataFilters
*/
private DataFilters $_filters;
private DataFilters $filters;

/**
* Constructor
*
* @param object $obj The object to use
* @param array $options Options
*/
public function __construct(object $obj, array $options = [])
final public function __construct(object $obj, array $options = [])
{
$this->_obj = new DataObject($obj);
$this->obj = new DataObject($obj);

if (isset($options['middleware'])) {
$this->_middleware = new Middleware($options['middleware']);
$this->_middleware->memoryLeakProtection();
$this->middleware = new Middleware($options['middleware']);
$this->middleware->memoryLeakProtection();
}

if (isset($options['validation'])) {
$this->_validation = new Validation($this->_obj, $options['validation']);
$this->_validation->validate();
$this->validation = new Validation($this->obj, $options['validation']);
$this->validation->validate();
}

if (isset($options['filters'])) {
$this->_filters = new DataFilters($options['filters']);
$this->filters = new DataFilters($options['filters']);
}
}

Expand All @@ -90,7 +90,8 @@ public function __construct(object $obj, array $options = [])
* @param mixed $data The mixed type of object data to use
* @param array $options Options
*
* @return static|bool
* @return static
* @throws Exception
*/
public static function instance($data, array $options = [])
{
Expand All @@ -114,7 +115,7 @@ public static function instance($data, array $options = [])
throw new Exception("Input data is not a valid object!\r\n" . print_r($data, true), 23);
}

return new self($data, $options);
return new static($data, $options);
}

/**
Expand All @@ -129,14 +130,14 @@ public static function instance($data, array $options = [])
*/
public function get(?string $path = '', $default = false)
{
$result = $this->_obj->get($path);
$result = $this->obj->get($path);

if ($result === false) {
return $default;
}

if (isset($this->_filters)) {
$result = $this->_filters->filter($path, $result);
if (isset($this->filters)) {
$result = $this->filters->filter($path, $result);
}

return $result;
Expand All @@ -153,7 +154,7 @@ public function get(?string $path = '', $default = false)
*/
public function set(string $path, $value): void
{
$this->_obj->set($path, $value);
$this->obj->set($path, $value);
}

/**
Expand All @@ -166,7 +167,7 @@ public function set(string $path, $value): void
*/
public function has(string $path): bool
{
return $this->_obj->has($path);
return $this->obj->has($path);
}

/**
Expand All @@ -176,7 +177,7 @@ public function has(string $path): bool
*/
public function toJson(): string
{
return json_encode($this->_obj);
return json_encode($this->obj);
}

/**
Expand All @@ -186,7 +187,7 @@ public function toJson(): string
*/
public function toArray(): array
{
return $this->_obj->toArray();
return $this->obj->toArray();
}

/**
Expand All @@ -198,7 +199,7 @@ public function toArray(): array
*/
public function isValid(string $path = ''): bool
{
return $this->_validation->isValid($path);
return $this->validation->isValid($path);
}

/**
Expand All @@ -210,6 +211,6 @@ public function isValid(string $path = ''): bool
*/
public function setMemoryLimit(int $memory): void
{
$this->_middleware->setMemoryLimit($memory);
$this->middleware->setMemoryLimit($memory);
}
}
10 changes: 0 additions & 10 deletions tests/TestDataFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,9 @@

class TestDataFilters extends TestCase
{
/**
* Test Constructor.
*/
public function __construct()
{
parent::__construct();
}

/**
* Fetches the raw JSON data as a string format
*
* @param boolean $isArray
*
* @return string
*/
public function getTestData()
Expand Down
10 changes: 0 additions & 10 deletions tests/TestDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,9 @@

class TestDataObject extends TestCase
{
/**
* Test Constructor.
*/
public function __construct()
{
parent::__construct();
}

/**
* Fetches the raw JSON data as a string format
*
* @param boolean $isArray
*
* @return string
*/
public function getTestData()
Expand Down
Loading
Loading