Skip to content

Commit

Permalink
Merge pull request #97 from chives/2.0
Browse files Browse the repository at this point in the history
Allow php8 and drop support for doctrine/persistence < 1.3
  • Loading branch information
szymach authored Feb 9, 2021
2 parents f8699f1 + 798448c commit b6371e3
Show file tree
Hide file tree
Showing 39 changed files with 1,106 additions and 985 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/vendor
/tests/temp
composer.lock
composer.phar
autoload.php
.phpcs-cache
.phpunit.result.cache
13 changes: 0 additions & 13 deletions .scrutinizer.yml

This file was deleted.

9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ matrix:
- php: 7.1
env:
- COMPOSER_FLAGS='--prefer-lowest'
- php: 7.2
- php: 7.3
- php: 7.4
- php: 8.0

sudo: false

Expand All @@ -20,4 +20,7 @@ before_script:
- composer validate
- composer update $COMPOSER_FLAGS

script: vendor/bin/phpunit
script:
- vendor/bin/phpcs
- vendor/bin/phpstan analyze -c phpstan.neon
- vendor/bin/phpunit
19 changes: 11 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
}
],
"require": {
"php": ">=7.1",
"symfony/event-dispatcher" : "^2.2|^3.0|^4.0",
"symfony/property-access": "^2.3|^3.0|^4.0",
"symfony/options-resolver": "^2.6|^3.0|^4.0",
"php": "^7.1|^8.0",
"symfony/event-dispatcher" : "^3.4|^4.0",
"symfony/property-access": "^3.4|^4.0|^5.0",
"symfony/options-resolver": "^3.4|^4.0|^5.0",
"fsi/reflection" : "0.9.*",
"fsi/data-indexer" : "0.9.*"
"fsi/data-indexer" : "0.9.*|^1.0"
},
"require-dev": {
"doctrine/orm": "^2.5",
"doctrine/common": "^2.5",
"gedmo/doctrine-extensions": "^2.3.10",
"phpunit/phpunit": "^7.1"
"doctrine/persistence": "^1.3|^2.0",
"gedmo/doctrine-extensions": "^2.3.10|^3.0",
"phpstan/phpstan": "^0.12.66",
"phpunit/phpunit": "^7.1|^8.0",
"squizlabs/php_codesniffer": "^3.4"
},
"autoload": {
"psr-4": {
Expand All @@ -40,6 +42,7 @@
"extra": {
"branch-alias": {
"dev-master": "3.0-dev",
"2.1": "2.1-dev",
"2.0": "2.0-dev",
"1.3": "1.3-dev",
"1.2": "1.2-dev",
Expand Down
4 changes: 3 additions & 1 deletion lib/Column/ColumnAbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ public function setOptions(array $options): void
public function getOption(string $name)
{
if (!array_key_exists($name, $this->options)) {
throw new UnknownOptionException(sprintf('Option "%s" is not available in column type "%s".', $name, $this->getId()));
throw new UnknownOptionException(
sprintf('Option "%s" is not available in column type "%s".', $name, $this->getId())
);
}

return $this->options[$name];
Expand Down
17 changes: 9 additions & 8 deletions lib/DataGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use FSi\Component\DataGrid\Data\DataRowsetInterface;
use FSi\Component\DataGrid\Column\ColumnTypeInterface;
use FSi\Component\DataGrid\Column\HeaderViewInterface;
use InvalidArgumentException;
use RuntimeException;

class DataGridView implements DataGridViewInterface
Expand Down Expand Up @@ -42,13 +43,13 @@ class DataGridView implements DataGridViewInterface
* @param string $name
* @param ColumnTypeInterface[] $columns
* @param DataRowsetInterface $rowset
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function __construct(string $name, array $columns = [], DataRowsetInterface $rowset)
public function __construct(string $name, array $columns, DataRowsetInterface $rowset)
{
foreach ($columns as $column) {
if (!$column instanceof ColumnTypeInterface) {
throw new \InvalidArgumentException('Column must implement FSi\Component\DataGrid\Column\ColumnTypeInterface');
throw new InvalidArgumentException(sprintf('Column must implement %s', ColumnTypeInterface::class));
}

$this->columns[$column->getName()] = $column;
Expand Down Expand Up @@ -95,7 +96,7 @@ public function getColumn(string $name): HeaderViewInterface
return $this->columnsHeaders[$name];
}

throw new \InvalidArgumentException(sprintf('Column "%s" does not exist in data grid.', $name));
throw new InvalidArgumentException(sprintf('Column "%s" does not exist in data grid.', $name));
}

public function getColumns(): array
Expand All @@ -111,7 +112,7 @@ public function clearColumns(): void
public function addColumn(HeaderViewInterface $column): void
{
if (!array_key_exists($column->getName(), $this->columns)) {
throw new \InvalidArgumentException(sprintf(
throw new InvalidArgumentException(sprintf(
'Column with name "%s" was never registred in datagrid "%s"',
$column->getName(),
$this->getName()
Expand All @@ -127,11 +128,11 @@ public function setColumns(array $columns): void

foreach ($columns as $column) {
if (!$column instanceof HeaderViewInterface) {
throw new \InvalidArgumentException('Column must implement FSi\Component\DataGrid\Column\HeaderViewInterface');
throw new InvalidArgumentException(sprintf('Column must implement %s', HeaderViewInterface::class));
}

if (!array_key_exists($column->getName(), $this->columns)) {
throw new \InvalidArgumentException(sprintf(
throw new InvalidArgumentException(sprintf(
'Column with name "%s" was never registred in datagrid "%s"',
$column->getName(),
$this->getName()
Expand Down Expand Up @@ -198,7 +199,7 @@ public function offsetGet($offset)
return new DataGridRowView($this, $this->getOriginColumns(), $this->rowset[$offset], $offset);
}

throw new \InvalidArgumentException(sprintf('Row "%s" does not exist in rowset.', $offset));
throw new InvalidArgumentException(sprintf('Row "%s" does not exist in rowset.', $offset));
}

public function offsetSet($offset, $value): void
Expand Down
28 changes: 23 additions & 5 deletions lib/DataMapper/ReflectionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,55 @@ public function getData(string $field, $object)

if ($objectReflection->hasMethod($getter)) {
if (!$objectReflection->getMethod($getter)->isPublic()) {
throw new DataMappingException(sprintf('Method "%s()" is not public in class "%s"', $getter, $objectReflection->name));
throw new DataMappingException(
sprintf('Method "%s()" is not public in class "%s"', $getter, $objectReflection->name)
);
}

return $object->$getter();
}

if ($objectReflection->hasMethod($isser)) {
if (!$objectReflection->getMethod($isser)->isPublic()) {
throw new DataMappingException(sprintf('Method "%s()" is not public in class "%s"', $isser, $objectReflection->name));
throw new DataMappingException(
sprintf('Method "%s()" is not public in class "%s"', $isser, $objectReflection->name)
);
}

return $object->$isser();
}

if ($objectReflection->hasMethod($hasser)) {
if (!$objectReflection->getMethod($hasser)->isPublic()) {
throw new DataMappingException(sprintf('Method "%s()" is not public in class "%s"', $hasser, $objectReflection->name));
throw new DataMappingException(
sprintf('Method "%s()" is not public in class "%s"', $hasser, $objectReflection->name)
);
}

return $object->$hasser();
}

if ($objectReflection->hasProperty($field)) {
if (!$objectReflection->getProperty($field)->isPublic()) {
throw new DataMappingException(sprintf('Property "%s" is not public in class "%s". Maybe you should create the method "%s()" or "%s()"?', $field, $objectReflection->name, $getter, $isser));
throw new DataMappingException(sprintf(
'Property "%s" is not public in class "%s". Maybe you should create the method "%s()" or "%s()"?',
$field,
$objectReflection->name,
$getter,
$isser
));
}
$property = $objectReflection->getProperty($field);
return $property->getValue($object);
}

throw new DataMappingException(sprintf('Neither property "%s" nor method "%s()" nor method "%s()" exists in class "%s"', $field, $getter, $isser, $objectReflection->name));
throw new DataMappingException(sprintf(
'Neither property "%s" nor method "%s()" nor method "%s()" exists in class "%s"',
$field,
$getter,
$isser,
$objectReflection->name
));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Extension/Core/ColumnType/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function filterValue($value)
$return[$name] = [];

$url = (isset($options['protocol'], $options['domain'])) ? $options['protocol'] . $options['domain'] : '';
$url .= vsprintf ($options['uri_scheme'], $value);
$url .= vsprintf($options['uri_scheme'], $value);

if (isset($options['redirect_uri']) && is_string($options['redirect_uri'])) {
if (strpos($url, '?') !== false) {
Expand Down
76 changes: 54 additions & 22 deletions lib/Extension/Core/ColumnType/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FSi\Component\DataGrid\Extension\Core\ColumnType;

use DateTimeInterface;
use FSi\Component\DataGrid\Column\ColumnAbstractType;
use FSi\Component\DataGrid\Exception\DataGridColumnException;

Expand Down Expand Up @@ -91,7 +92,8 @@ private function getInputData($value)
case 'array':
if (!isset($mappingFormat)) {
throw new DataGridColumnException(
'"input_field_format" option is missing. Example: "input_field_format" => array("mapping_field_name" => array("input" => "datetime"))'
'"input_field_format" option is missing. Example: '
. '"input_field_format" => array("mapping_field_name" => array("input" => "datetime"))'
);
}
if (!is_array($mappingFormat)) {
Expand All @@ -101,7 +103,8 @@ private function getInputData($value)
}
if (count($mappingFormat) !== count($value)) {
throw new DataGridColumnException(
'"input_field_format" option value array must have same count as "field_mapping" option value array. '
'"input_field_format" option value array must have same count as "field_mapping" option'
. ' value array. '
);
}

Expand All @@ -122,10 +125,15 @@ private function getInputData($value)

switch (strtolower($fieldInputType)) {
case 'string':
$mappingFormat = (array_key_exists('datetime_format', $inputType)) ? $inputType['datetime_format'] : null;
$mappingFormat = array_key_exists('datetime_format', $inputType)
? $inputType['datetime_format']
: null;
if (null === $mappingFormat) {
throw new DataGridColumnException(
sprintf('"datetime_format" option is required in "input_field_format" for field "%s".', $field)
sprintf(
'"datetime_format" option is required in "input_field_format" for field "%s".',
$field
)
);
}
if (empty($value[$field])) {
Expand All @@ -145,7 +153,11 @@ private function getInputData($value)
case 'datetime':
if (!empty($value[$field]) && !($value[$field] instanceof \DateTime)) {
throw new DataGridColumnException(
sprintf('Value in field "%s" is "%s" type instead of "\DateTime" instance.', $field, gettype($value[$field]))
sprintf(
'Value in field "%s" is "%s" type instead of "\DateTime" instance.',
$field,
gettype($value[$field])
)
);
}

Expand All @@ -154,24 +166,33 @@ private function getInputData($value)
case 'datetime_interface':
if (!interface_exists(\DateTimeInterface::class)) {
throw new DataGridColumnException(
'Input type option has value "datetime_interface" but \DateTimeInterface is not defined'
sprintf(
'Input type option has value "datetime_interface" but %s is not defined',
DateTimeInterface::class
)
);
}

if (!empty($value[$field]) && !($value[$field] instanceof \DateTimeInterface)) {
throw new DataGridColumnException(
sprintf('Value in field "%s" is "%s" type instead of "\DateTimeInterface" instance.',
$field, gettype($value[$field]))
sprintf(
'Value in field "%s" is "%s" type instead of "\DateTimeInterface" instance.',
$field,
gettype($value[$field])
)
);
}

$inputData[$field] = $value[$field];
break;
default:
throw new DataGridColumnException(
sprintf('"%s" is not valid input option value for field "%s". '.
'You should consider using one of "array", "string", "datetime" or "timestamp" input option values. ', $fieldInputType, $field)
);
throw new DataGridColumnException(sprintf(
'"%s" is not valid input option value for field "%s". '
. 'You should consider using one of "array", "string", "datetime" or "timestamp" '
. ' input option values. ',
$fieldInputType,
$field
));
}
}
break;
Expand All @@ -186,11 +207,12 @@ private function getInputData($value)
);
}

if (empty($value)) {
$inputData[$field] = null;
} else {
$inputData[$field] = $this->transformStringToDateTime($value, $mappingFormat);
}
if (empty($value)) {
$inputData[$field] = null;
} else {
$inputData[$field] = $this->transformStringToDateTime($value, $mappingFormat);
}

break;

case 'datetime':
Expand Down Expand Up @@ -238,8 +260,12 @@ private function getInputData($value)

default:
throw new DataGridColumnException(
sprintf('"%s" is not valid input option value. '.
'You should consider using one of "array", "string", "datetime" or "timestamp" input option values. ', $inputType)
sprintf(
'"%s" is not valid input option value. '
. 'You should consider using one of "array", "string", "datetime" or "timestamp" input '
. 'option values. ',
$inputType
)
);
}

Expand All @@ -251,7 +277,7 @@ private function guessInputType($value): ?string
if (is_array($value)) {
if (count($value) > 1) {
throw new DataGridColumnException(
'If you want to use more that one mapping fields you need to set "input" option value "array".'
'If you want to use more that one mapping fields you need to set "input" option value "array".'
);
}
$value = current($value);
Expand Down Expand Up @@ -286,7 +312,8 @@ private function transformStringToDateTime(?string $value, $mappingFormat): \Dat

if (!is_string($mappingFormat)) {
throw new DataGridColumnException(
'When using input type "string", "mapping_fields_format" option must be an string that contains valid data format'
'When using input type "string", "mapping_fields_format" option must be an string that contains '
. 'valid data format'
);
}

Expand All @@ -305,7 +332,12 @@ private function transformTimestampToDateTime($value): \DateTime
{
if (!is_numeric($value)) {
throw new \InvalidArgumentException(
sprintf('Value in column "%s" should be timestamp but "%s" type was detected. Maybe you should consider using different "input" opition value?', $this->getName(), gettype($value))
sprintf(
'Value in column "%s" should be timestamp but "%s" type was detected.'
. ' Maybe you should consider using different "input" option value?',
$this->getName(),
gettype($value)
)
);
}

Expand Down
Loading

0 comments on commit b6371e3

Please sign in to comment.