Skip to content

Commit

Permalink
Merge pull request #4 from byjg/5.0
Browse files Browse the repository at this point in the history
Migrate to PHP 8.1
  • Loading branch information
byjg authored Oct 27, 2024
2 parents 3584742 + 1284d7e commit 348e980
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 321 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: byjg
3 changes: 1 addition & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ jobs:
strategy:
matrix:
php-version:
- "8.3"
- "8.2"
- "8.1"
- "8.0"
- "7.4"

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .run/Tests.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tests" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml.dist" scope="XML" use_alternative_configuration_file="true" />
<method v="2" />
</configuration>
</component>
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ $file = "".
"002GILBERTS1621\n";

$fieldDefinition = [
new \ByJG\AnyDataset\Text\Enum\FixedTextDefinition('id', 0, 3, FixedTextDefinition::TYPE_NUMBER),
new \ByJG\AnyDataset\Text\Enum\FixedTextDefinition('name', 3, 7, FixedTextDefinition::TYPE_STRING),
new \ByJG\AnyDataset\Text\Enum\FixedTextDefinition('enable', 10, 1, FixedTextDefinition::TYPE_STRING, ['S', 'N']), // Required values --> S or N
new \ByJG\AnyDataset\Text\Enum\FixedTextDefinition('code', 11, 4, FixedTextDefinition::TYPE_NUMBER),
new \ByJG\AnyDataset\Text\Definition\FixedTextDefinition('id', 0, 3, FixedTextDefinition::TYPE_NUMBER),
new \ByJG\AnyDataset\Text\Definition\FixedTextDefinition('name', 3, 7, FixedTextDefinition::TYPE_STRING),
new \ByJG\AnyDataset\Text\Definition\FixedTextDefinition('enable', 10, 1, FixedTextDefinition::TYPE_STRING, ['S', 'N']), // Required values --> S or N
new \ByJG\AnyDataset\Text\Definition\FixedTextDefinition('code', 11, 4, FixedTextDefinition::TYPE_NUMBER),
];

$dataset = new \ByJG\AnyDataset\Text\FixedTextFileDataset($file)
Expand All @@ -130,21 +130,21 @@ $file = "".
"002GILBERTS1621\n";

$fieldDefinition = [
new \ByJG\AnyDataset\Text\Enum\FixedTextDefinition('id', 0, 3),
new \ByJG\AnyDataset\Text\Enum\FixedTextDefinition('name', 3, 7),
new \ByJG\AnyDataset\Text\Enum\FixedTextDefinition(
new \ByJG\AnyDataset\Text\Definition\FixedTextDefinition('id', 0, 3),
new \ByJG\AnyDataset\Text\Definition\FixedTextDefinition('name', 3, 7),
new \ByJG\AnyDataset\Text\Definition\FixedTextDefinition(
'enable',
10,
1,
FixedTextDefinition::TYPE_STRING,
null,
[
"S" => [
new \ByJG\AnyDataset\Text\Enum\FixedTextDefinition('first', 11, 1),
new \ByJG\AnyDataset\Text\Enum\FixedTextDefinition('second', 12, 3),
new \ByJG\AnyDataset\Text\Definition\FixedTextDefinition('first', 11, 1),
new \ByJG\AnyDataset\Text\Definition\FixedTextDefinition('second', 12, 3),
],
"N" => [
new \ByJG\AnyDataset\Text\Enum\FixedTextDefinition('reason', 11, 4),
new \ByJG\AnyDataset\Text\Definition\FixedTextDefinition('reason', 11, 4),
]
]
),
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"php": ">=7.4",
"byjg/anydataset": "4.9.*"
"php": ">=8.1 <8.4",
"byjg/anydataset": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "5.7.*|7.4.*|^9.5",
"vimeo/psalm": "^4.24"
"phpunit/phpunit": "^9.6",
"vimeo/psalm": "^6.0"
},
"provide": {
"byjg/anydataset-implementation": "1.0"
Expand Down
7 changes: 5 additions & 2 deletions psalm.xml.dist → psalm.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
errorLevel="4"
resolveFromConfigFile="true"
findUnusedBaselineEntry="true"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<directory name="tests" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
</psalm>
52 changes: 52 additions & 0 deletions src/Definition/FixedTextDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace ByJG\AnyDataset\Text\Definition;

use InvalidArgumentException;

/**
* @package xmlnuke
*/
class FixedTextDefinition
{
/** @var string */
public string $fieldName;

/** @var int */
public int $startPos;

/** @var int */
public int $length;

/** @var ?array */
public ?array $requiredValue;

/** @var TextTypeEnum */
public TextTypeEnum $type;

/** @var array|null */
public ?array $subTypes = [];

/**
*
* @param string $fieldName
* @param int $startPos
* @param int $length
* @param TextTypeEnum $type
* @param ?array $requiredValue
* @param array|null $subTypes
*/
public function __construct(string $fieldName, int $startPos, int $length, TextTypeEnum $type = TextTypeEnum::STRING, ?array $requiredValue = null, array $subTypes = null)
{
$this->fieldName = $fieldName;
$this->startPos = $startPos;
$this->length = $length;
$this->type = $type;
$this->requiredValue = $requiredValue;
$this->subTypes = $subTypes;

if ($this->type != TextTypeEnum::NUMBER && $this->type != TextTypeEnum::STRING) {
throw new InvalidArgumentException("Type must be 'string' or 'number'");
}
}
}
9 changes: 9 additions & 0 deletions src/Definition/TextTypeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace ByJG\AnyDataset\Text\Definition;

enum TextTypeEnum
{
case STRING;
case NUMBER;
}
62 changes: 0 additions & 62 deletions src/Enum/FixedTextDefinition.php

This file was deleted.

33 changes: 13 additions & 20 deletions src/FixedTextFileDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace ByJG\AnyDataset\Text;

use ByJG\AnyDataset\Core\GenericIterator;
use ByJG\AnyDataset\Text\Enum\FixedTextDefinition;
use ByJG\AnyDataset\Core\Exception\DatasetException;
use ByJG\AnyDataset\Core\Exception\NotFoundException;
use ByJG\AnyDataset\Core\GenericIterator;
use ByJG\AnyDataset\Text\Definition\FixedTextDefinition;
use Exception;
use InvalidArgumentException;

Expand All @@ -15,26 +15,25 @@ class FixedTextFileDataset
/**
* @var string
*/
protected $source;
protected string $source;

/**
* @var FixedTextDefinition[]
* @psalm-suppress PossiblyNullPropertyAssignmentValue
*/
protected $fieldDefinition = null;
protected ?array $fieldDefinition = null;

/**
* @var string
*/
protected $sourceType;
protected string $sourceType;

/**
* Text File Data Set
*
* @param string $source
* @throws NotFoundException
*/
protected function __construct($source)
protected function __construct(string $source)
{
$this->source = $source;
$this->sourceType = "HTTP";
Expand All @@ -53,25 +52,19 @@ protected function __construct($source)
*
* @param string $source
* @return FixedTextFileDataset
* @throws NotFoundException
*/
public static function getInstance($source)
public static function getInstance(string $source): FixedTextFileDataset
{
return new FixedTextFileDataset($source);
}

/**
* @param FixedTextDefinition[] $fieldDefinition
* @return FixedTextFileDataset
* @return static
*/
public function withFieldDefinition($fieldDefinition)
public function withFieldDefinition(array $fieldDefinition): static
{
/**
* @psalm-suppress DocblockTypeContradiction
*/
if (!is_array($fieldDefinition)) {
throw new InvalidArgumentException("You must define an array of FixedTextDefinition class.");
}

$this->fieldDefinition = $fieldDefinition;

return $this;
Expand All @@ -83,7 +76,7 @@ public function withFieldDefinition($fieldDefinition)
* @throws DatasetException
* @throws Exception
*/
public function getIterator()
public function getIterator(): GenericIterator
{
if (empty($this->fieldDefinition)) {
throw new InvalidArgumentException("Field definition is empty");
Expand All @@ -99,7 +92,7 @@ public function getIterator()
* @return GenericIterator
* @throws DatasetException
*/
protected function getIteratorHttp()
protected function getIteratorHttp(): GenericIterator
{
// Expression Regular:
// [1]: http or ftp
Expand Down Expand Up @@ -131,7 +124,7 @@ protected function getIteratorHttp()
* @return GenericIterator
* @throws DatasetException
*/
protected function getIteratorFile()
protected function getIteratorFile(): GenericIterator
{
$handle = fopen($this->source, "r");
if (!$handle) {
Expand Down
Loading

0 comments on commit 348e980

Please sign in to comment.