-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b549555
Showing
28 changed files
with
916 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.DS_Store | ||
vendor/ | ||
composer.lock | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# .scrutinizer.yml | ||
|
||
checks: | ||
php: | ||
code_rating: true | ||
duplication: true | ||
build: | ||
environment: | ||
php: '5.6' | ||
dependencies: | ||
before: | ||
- mysql -e "CREATE DATABASE test" | ||
tests: | ||
override: | ||
- | ||
command: 'phpunit --coverage-clover=.soupmix_coverage' | ||
coverage: | ||
file: '.soupmix_coverage' | ||
format: 'clover' | ||
filter: | ||
excluded_paths: | ||
- "tests/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
language: php | ||
|
||
sudo: false | ||
|
||
php: | ||
- 7.1 | ||
- 7.0 | ||
|
||
before_script: | ||
- composer install -n | ||
|
||
script: | ||
- phpunit --coverage-clover build/logs/clover.xml | ||
|
||
after_script: | ||
- if [ $TRAVIS_PHP_VERSION >= '7.0' ]; then php vendor/bin/coveralls; fi | ||
|
||
after_success: | ||
- travis_retry php vendor/bin/coveralls -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 <Mehmet Korkmaz [email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Selami Entity | ||
|
||
[![Build Status](https://api.travis-ci.org/selamiphp/entity.svg?branch=master)](https://travis-ci.org/selamiphp/entity) [![Coverage Status](https://coveralls.io/repos/github/selamiphp/entity/badge.svg?branch=master)](https://coveralls.io/github/selamiphp/entity?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/selamiphp/entity/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/selamiphp/entity/) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/748983d7d23e4c26b13dd76fc781cdc8)](https://www.codacy.com/app/mehmet/views?utm_source=github.com&utm_medium=referral&utm_content=selamiphp/entity&utm_campaign=Badge_Grade) [![Latest Stable Version](https://poser.pugx.org/selami/entity/v/stable)](https://packagist.org/packages/selami/entity) [![Total Downloads](https://poser.pugx.org/selami/entity/downloads)](https://packagist.org/packages/selami/entity) [![Latest Unstable Version](https://poser.pugx.org/selami/entity/v/unstable)](https://packagist.org/packages/selami/entity) [![License](https://poser.pugx.org/selami/entity/license)](https://packagist.org/packages/selami/entity) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "selami/entity", | ||
"description": "A library to validate variable types, to fix, to sanitize and to set default values for a model definition.", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Mehmet Korkmaz", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": "~7.0||~7.1", | ||
"beberlei/assert": "~2.7.0", | ||
"crisu83/shortid": "~1.0", | ||
"ezyang/htmlpurifier": "~4.8", | ||
"seld/jsonlint": "^1.5" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.7.5", | ||
"phpunit/phpcov": "^3.1", | ||
"satooshi/php-coveralls": "^1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Selami\\Entity\\": "src/" | ||
}, | ||
"files":[ | ||
"src/functions.php" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="true" | ||
syntaxCheck="true" | ||
bootstrap="tests/bootstrap.php" | ||
> | ||
<php> | ||
<ini name="memory_limit" value="-1"/> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="Soupmix SQL Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<groups> | ||
<exclude> | ||
<group>benchmark</group> | ||
</exclude> | ||
</groups> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-clover" target="build/clover.xml"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
|
||
namespace Selami\Entity\Exception; | ||
|
||
|
||
use InvalidArgumentException; | ||
|
||
class FileNotFoundException extends InvalidArgumentException | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Selami\Entity\Interfaces; | ||
|
||
|
||
use UnexpectedValueException; | ||
|
||
interface ParserInterface | ||
{ | ||
/** | ||
* @return array | ||
* @throws UnexpectedValueException | ||
*/ | ||
public function parse(); | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function checkFormat(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Selami\Entity\Parser; | ||
|
||
use Selami\Entity\Interfaces\ParserInterface; | ||
use UnexpectedValueException; | ||
use Selami\Entity\Exception\FileNotFoundException; | ||
|
||
|
||
/** | ||
* Config Ini Parser | ||
* @package Selami\Entity\Parser | ||
*/ | ||
class ConfigIni implements ParserInterface | ||
{ | ||
protected $schemaConfig; | ||
|
||
/** | ||
* Config constructor. | ||
* @param string $schemaConfig | ||
* @param bool $is_file | ||
* @throws FileNotFoundException | ||
*/ | ||
public function __construct(string $schemaConfig, bool $is_file = false) | ||
{ | ||
if ($is_file && !file_exists($schemaConfig)) { | ||
$message = sprintf('File: %s not found. please provide full path for file names', $schemaConfig); | ||
throw new FileNotFoundException($message); | ||
} | ||
$this->schemaConfig = $is_file ? file_get_contents($schemaConfig) : $schemaConfig; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function parse() | ||
{ | ||
$schema = @parse_ini_string($this->schemaConfig, true); | ||
if ($schema === false) { | ||
$message = error_get_last(); | ||
throw new UnexpectedValueException($message['message']); | ||
} | ||
return ['schema' => $schema]; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function checkFormat() | ||
{ | ||
$schema = @parse_ini_string($this->schemaConfig, true); | ||
return $schema !== false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Selami\Entity\Parser; | ||
|
||
use Selami\Entity\Interfaces\ParserInterface; | ||
use Seld\JsonLint\JsonParser; | ||
use UnexpectedValueException; | ||
use Selami\Entity\Exception\FileNotFoundException; | ||
|
||
/** | ||
* Json Parser | ||
* @package Selami\Entity\Parser | ||
*/ | ||
class Json implements ParserInterface | ||
{ | ||
protected $schemaConfig; | ||
|
||
/** | ||
* Json constructor. | ||
* @param string $schemaConfig | ||
* @param bool $is_file | ||
* @throws FileNotFoundException | ||
*/ | ||
public function __construct(string $schemaConfig, bool $is_file = false) | ||
{ | ||
if ($is_file && !file_exists($schemaConfig)) { | ||
$message = sprintf('File: %s not found. please provide full path for file names', $schemaConfig); | ||
throw new FileNotFoundException($message); | ||
} | ||
$this->schemaConfig = $is_file ? file_get_contents($schemaConfig) : $schemaConfig; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function parse() | ||
{ | ||
$schema = json_decode($this->schemaConfig, true); | ||
if (json_last_error() !== JSON_ERROR_NONE) { | ||
$parser = new JsonParser(); | ||
$linting = $parser->lint($this->schemaConfig); | ||
throw new UnexpectedValueException($linting->getMessage()); | ||
} | ||
return $schema; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function checkFormat() | ||
{ | ||
$parser = new JsonParser(); | ||
$linting = $parser->lint($this->schemaConfig); | ||
return $linting === null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Selami\Entity\Parser; | ||
|
||
use Selami\Entity\Interfaces\ParserInterface; | ||
use UnexpectedValueException; | ||
use Selami\Entity\Exception\FileNotFoundException; | ||
|
||
|
||
/** | ||
* Array Parser | ||
* @package Selami\Entity\Parser | ||
*/ | ||
class PhpArray implements ParserInterface | ||
{ | ||
protected $schemaConfig; | ||
|
||
/** | ||
* Config constructor. | ||
* @param string $schemaConfig | ||
* @throws FileNotFoundException | ||
*/ | ||
public function __construct(string $schemaConfig) | ||
{ | ||
if (!file_exists($schemaConfig)) { | ||
$message = sprintf('File: %s not found. please provide full path for file names', $schemaConfig); | ||
throw new FileNotFoundException($message); | ||
} | ||
$this->schemaConfig = $schemaConfig; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function parse() | ||
{ | ||
try{ | ||
$schema = require $this->schemaConfig; | ||
} catch (\AssertionError $e) { | ||
throw new UnexpectedValueException($e->getMessage()); | ||
|
||
} catch (\Error $e) { | ||
throw new UnexpectedValueException($e->getMessage()); | ||
} | ||
if (!is_array($schema)) { | ||
throw new UnexpectedValueException('Config file does not return an array.'); | ||
} | ||
|
||
return $schema; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function checkFormat() | ||
{ | ||
try { | ||
require $this->schemaConfig; | ||
return true; | ||
} catch (\ParseError $e) { | ||
} catch (\TypeError $e) { | ||
} catch (\DivisionByZeroError $e) { | ||
} catch (\ArithmeticError $e) { | ||
} catch (\AssertionError $e) { | ||
} catch (\Error $e) { | ||
} | ||
return false; | ||
|
||
} | ||
} |
Oops, something went wrong.