Skip to content

Commit

Permalink
-Change default rule from PS2 to Symphony (#8)
Browse files Browse the repository at this point in the history
-Removed rules that are already default in Symphony
-Added rule to sort imports in Alphabetical order
  • Loading branch information
hoshomoh authored Oct 13, 2018
1 parent d356ec5 commit 2b9dd52
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 154 deletions.
9 changes: 2 additions & 7 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'concat_space' => ['spacing' => 'one'],
'no_empty_statement' => true,
'no_unused_imports' => true,
'no_whitespace_in_blank_line' => true,
'phpdoc_scalar' => true,
'phpdoc_inline_tag' => true,
'trailing_comma_in_multiline_array' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
])
->setUsingCache(false)
->setFinder(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ Run `composer test` from the root of the Package.
### Contributing to this Repo

Feel free to submit a pull request for a feature or bug fix. However, do note that before your pull request can be merged it must have test written or updated as the case maybe.
The project run's automatic checks for PSR-1 and PSR-2 code standards using [php-cs-fixer](https://symfony.com/doc/current/contributing/code/standards.html).
The project run's automatic checks to make sure that the Symphony code standards are met using [php-cs-fixer](https://symfony.com/doc/current/contributing/code/standards.html).

So, before pushing or making any pull request run the below command:

Expand Down
11 changes: 6 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

require 'vendor/autoload.php';

use Oshomo\CsvUtils\Converter\JsonConverter;
use Oshomo\CsvUtils\Converter\XmlConverter;
use Oshomo\CsvUtils\Validator\Validator;

$file_path = realpath(dirname(__FILE__));
$file = $file_path . "/sample/sample.csv";
$file = $file_path . '/sample/sample.csv';
$validator = new Validator($file, ',', [
"stars" => ["between:0,5"],
"name" => ["ascii_only"],
"uri" => ["url", function ($value, $fail) {
if (strpos($value, "https://") !== 0) {
'stars' => ['between:0,5'],
'name' => ['ascii_only'],
'uri' => ['url', function ($value, $fail) {
if (0 !== strpos($value, 'https://')) {
return $fail('The URL passed must be https i.e it must start with https://');
}
}],
Expand Down
4 changes: 2 additions & 2 deletions src/Contracts/ConverterHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface ConverterHandlerInterface
{
/**
* Get the converter file extension. If the file extension
* for this converter is csv just return "csv"
* for this converter is csv just return "csv".
*
* @return string
*/
Expand All @@ -23,7 +23,7 @@ public function getExtension();
public function convert($data);

/**
* Writes the converted data to the path specified
* Writes the converted data to the path specified.
*
* @param string $filename
*
Expand Down
12 changes: 6 additions & 6 deletions src/Contracts/ValidationRuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ interface ValidationRuleInterface
/**
* Get the number of parameters that should be supplied.
* If no parameter should be supplied return 0 else
* return the number of parameters that should be returned
* return the number of parameters that should be returned.
*
* @return int
*/
public function parameterCount();

/**
* Determines if the validation rule passes. This is where we do the
* actual validation. If the validation passes return true else false
* actual validation. If the validation passes return true else false.
*
* @param mixed $value
* @param mixed $value
* @param array $parameters
*
* @return bool
Expand All @@ -27,7 +27,7 @@ public function passes($value, $parameters);
/**
* Get the validation error message. Specify the message that should
* be returned if the validation fails. You can make use of the
* :attribute and :value placeholders in the message string
* :attribute and :value placeholders in the message string.
*
* @return string
*/
Expand All @@ -42,10 +42,10 @@ public function message();
* [':custom_a', ':custom_b'],
* [$parameters[0], $parameters[1]],
* $message
* );
* );.
*
* @param string $message
* @param array $parameters
* @param array $parameters
*
* @return string
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Converter/JsonConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class JsonConverter implements ConverterHandlerInterface
{
const FILE_EXTENSION = "json";
const FILE_EXTENSION = 'json';

/**
* The converted data
* The converted data.
*
* @var string
*/
Expand Down
11 changes: 5 additions & 6 deletions src/Converter/XmlConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@

class XmlConverter implements ConverterHandlerInterface
{
const FILE_EXTENSION = "xml";
const DEFAULT_ROOT_ELEMENT = "data";
const DEFAULT_RECORD_ELEMENT = "item";
const FILE_EXTENSION = 'xml';
const DEFAULT_ROOT_ELEMENT = 'data';
const DEFAULT_RECORD_ELEMENT = 'item';

/**
* XML node root element
* XML node root element.
*/
protected $recordElement;

/**
* The converted data
* The converted data.
*
* @var string
*/
protected $data;


/**
* XmlConverter constructor.
*
Expand Down
14 changes: 7 additions & 7 deletions src/Helpers/FormatsMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ trait FormatsMessages
/**
* Get the validation message for an attribute and rule.
*
* @param string $attribute
* @param string $attribute
* @param ValidationRuleInterface $rule
* @param string $actualRule
* @param string $actualRule
*
* @return string
*/
protected function getMessage($attribute, $rule, $actualRule)
{
$inlineMessage = $this->getInlineMessage($attribute, $actualRule);

if (! is_null($inlineMessage)) {
if (!is_null($inlineMessage)) {
return $inlineMessage;
}

Expand Down Expand Up @@ -81,11 +81,11 @@ protected function ruleToLower($rule)
/**
* Replace all error message place-holders with actual values.
*
* @param string $message
* @param string $attribute
* @param mixed $value
* @param string $message
* @param string $attribute
* @param mixed $value
* @param ValidationRuleInterface $rule
* @param array $parameters
* @param array $parameters
*
* @return string
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Rules/AsciiOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class AsciiOnly implements ValidationRuleInterface
{
/**
* Get the number of parameters that should be supplied
* Get the number of parameters that should be supplied.
*
* @return int
*/
Expand All @@ -19,7 +19,7 @@ public function parameterCount()
/**
* Determine if the validation rule passes.
*
* @param mixed $value
* @param mixed $value
* @param $parameters
*
* @return bool
Expand All @@ -36,14 +36,14 @@ public function passes($value, $parameters)
*/
public function message()
{
return "The :attribute value :value contains a non-ascii character";
return 'The :attribute value :value contains a non-ascii character';
}

/**
* Replace error messages parameter with right values.
*
* @param string $message
* @param array $parameters
* @param array $parameters
*
* @return string
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Rules/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public function passes($value, $parameters)
*/
public function message()
{
return "The :attribute value :value is not between :min - :max.";
return 'The :attribute value :value is not between :min - :max.';
}

/**
* Replace error messages parameter with right values
* Replace error messages parameter with right values.
*
* @param string $message
* @param array $parameters
* @param array $parameters
*
* @return string
*/
Expand Down
10 changes: 4 additions & 6 deletions src/Rules/ClosureValidationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class ClosureValidationRule implements ValidationRuleInterface
/**
* Create a new Closure based validation rule.
*
* @param \Closure $callback
*
* @return void
* @param \Closure $callback
*/
public function __construct($callback)
{
Expand All @@ -52,7 +50,7 @@ public function parameterCount()
/**
* Determine if the validation rule passes.
*
* @param mixed $value
* @param mixed $value
* @param $parameters
*
* @return bool
Expand All @@ -67,7 +65,7 @@ public function passes($value, $parameters)
$this->message = $message;
});

return ! $this->failed;
return !$this->failed;
}

/**
Expand All @@ -84,7 +82,7 @@ public function message()
* Replace error messages parameter with right values.
*
* @param string $message
* @param array $parameters
* @param array $parameters
*
* @return string
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public function passes($value, $parameters)
*/
public function message()
{
return "The :attribute value :value is not a valid url";
return 'The :attribute value :value is not a valid url';
}

/**
* Replace error messages parameter with right values.
*
* @param string $message
* @param array $parameters
* @param array $parameters
*
* @return string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/ValidationRuleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected static function parseStringRule($rule)
// The format for specifying validation rules and parameters follows an
// easy {rule}:{parameters} formatting convention. For instance the
// rule "Between:3,5" states that the value may only be between 3 - 5.
if (strpos($rule, ':') !== false) {
if (false !== strpos($rule, ':')) {
list($rule, $parameter) = explode(':', $rule, 2);

$parameters = static::parseParameters($parameter);
Expand Down
Loading

0 comments on commit 2b9dd52

Please sign in to comment.