Skip to content

Commit

Permalink
Merge 7df9080 into dfe3a08
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Jul 20, 2022
2 parents dfe3a08 + 7df9080 commit 70e3039
Show file tree
Hide file tree
Showing 24 changed files with 532 additions and 192 deletions.
1 change: 1 addition & 0 deletions .github/workflows/phpunit.yml
Expand Up @@ -29,6 +29,7 @@ jobs:
- uses: actions/checkout@v2
- run: composer install
- run: ./vendor/bin/phpunit
- run: ./vendor/bin/psalm

Documentation:
runs-on: 'ubuntu-latest'
Expand Down
18 changes: 18 additions & 0 deletions .gitpod.yml
@@ -0,0 +1,18 @@
tasks:
- init: |
echo "No special initialization"
command: |
composer install
image:
file: .gitpod/Dockerfile

vscode:
extensions:
- ikappas.composer
- felixfbecker.php-debug
- neilbrayfield.php-docblocker
- bmewburn.vscode-intelephense-client
- getpsalm.psalm-vscode-plugin
- SonarSource.sonarlint-vscode
- recca0120.vscode-phpunit
4 changes: 4 additions & 0 deletions .gitpod/Dockerfile
@@ -0,0 +1,4 @@
# You can find the new timestamped tags here: https://hub.docker.com/r/gitpod/workspace-full/tags
FROM gitpod/workspace-full:latest

RUN sudo install-packages php-xdebug
38 changes: 38 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,38 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug current Script in Console",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "PHPUnit Debug",
"type": "php",
"request": "launch",
"program": "${workspaceFolder}/vendor/bin/phpunit",
"cwd": "${workspaceFolder}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
}
]
}
5 changes: 3 additions & 2 deletions composer.json
Expand Up @@ -11,13 +11,14 @@
"require": {
"php": ">=5.6.0",
"byjg/xmlutil": "1.0.*",
"byjg/serializer": "1.0.*"
"byjg/serializer": "dev-major_refactory"
},
"suggest": {
"ext-dom": "*"
},
"require-dev": {
"phpunit/phpunit": "5.7.*|7.4.*|^9.5"
"phpunit/phpunit": "5.7.*|7.4.*|^9.5",
"vimeo/psalm": "^4.24"
},
"license": "MIT"
}
1 change: 1 addition & 0 deletions phpunit.xml.dist
Expand Up @@ -11,6 +11,7 @@ and open the template in the editor.
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
stopOnFailure="false">

<php>
Expand Down
15 changes: 15 additions & 0 deletions psalm.xml.dist
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
resolveFromConfigFile="true"
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" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
46 changes: 30 additions & 16 deletions src/AnyDataset.php
Expand Up @@ -58,12 +58,12 @@ class AnyDataset

/**
* Path to anydataset file
* @var string
* @var string|null
*/
private $filename;

/**
* @param string $filename
* @param null|string $filename
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
* @throws \ByJG\Util\Exception\XmlUtilException
*/
Expand All @@ -80,18 +80,23 @@ public function __construct($filename = null)
});
}

/**
* @return string|null
*/
public function getFilename()
{
return $this->filename;
}

/**
*
* @param string|null $file
* @param mixed $closure
* @return void
*/
private function defineSavePath($file, $closure)
{
if (!is_null($file)) {
if (!is_string($file)) {
throw new InvalidArgumentException('I expected a string as a file name');
}

$ext = pathinfo($file, PATHINFO_EXTENSION);
if (empty($ext) && substr($file, 0, 6) !== "php://") {
$file .= '.anydata.xml';
Expand All @@ -106,6 +111,7 @@ private function defineSavePath($file, $closure)
* Private method used to read and populate anydataset class from specified file
*
* @param string $filepath Path and Filename to be read
* @return void
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
* @throws \ByJG\Util\Exception\XmlUtilException
*/
Expand All @@ -121,7 +127,7 @@ private function createFrom($filepath)
$fields = $row->getElementsByTagName("field");
foreach ($fields as $field) {
$attr = $field->attributes->getNamedItem("name");
if (is_null($attr)) {
if (is_null($attr) || is_null($attr->nodeValue)) {
throw new InvalidArgumentException('Malformed anydataset file ' . basename($filepath));
}

Expand All @@ -146,7 +152,8 @@ public function xml()
}

/**
* @param string $filename
* @param string|null $filename
* @return void
* @throws DatabaseException
* @throws \ByJG\Util\Exception\XmlUtilException
*/
Expand All @@ -164,7 +171,7 @@ public function save($filename = null)
/**
* Append one row to AnyDataset.
*
* @param Row|array|\stdClass|object $singleRow
* @param Row|array|\stdClass|object|null $singleRow
* @return void
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
*/
Expand All @@ -191,6 +198,7 @@ public function appendRow($singleRow = [])
* Enter description here...
*
* @param GenericIterator $iterator
* @return void
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
*/
public function import($iterator)
Expand All @@ -204,10 +212,11 @@ public function import($iterator)
* Insert one row before specified position.
*
* @param int $rowNumber
* @param mixed $row
* @param Row|array|\stdClass|object $row
* @return void
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
*/
public function insertRowBefore($rowNumber, $row = null)
public function insertRowBefore($rowNumber, $row)
{
if ($rowNumber > count($this->collection)) {
$this->appendRow($row);
Expand All @@ -216,14 +225,22 @@ public function insertRowBefore($rowNumber, $row = null)
if (!($row instanceof Row)) {
$singleRow = new Row($row);
}

/**
* @psalm-suppress InvalidPropertyAssignmentValue
*/
array_splice($this->collection, $rowNumber, 0, '');
/**
* @psalm-suppress InvalidPropertyAssignmentValue
*/
$this->collection[$rowNumber] = $singleRow;
}
}

/**
*
* @param mixed $row
* @return void
* @throws \ByJG\Serializer\Exception\InvalidArgumentException
*/
public function removeRow($row = null)
Expand Down Expand Up @@ -291,8 +308,7 @@ public function getArray($fieldName, $itf = null)
{
$iterator = $this->getIterator($itf);
$result = array();
while ($iterator->hasNext()) {
$singleRow = $iterator->moveNext();
foreach ($iterator as $singleRow) {
$result[] = $singleRow->get($fieldName);
}
return $result;
Expand All @@ -310,13 +326,11 @@ public function sort($field)
}

$this->collection = $this->quickSortExec($this->collection, $field);

return;
}

/**
* @param Row[] $seq
* @param $field
* @param string $field
* @return array
*/
protected function quickSortExec($seq, $field)
Expand Down
13 changes: 6 additions & 7 deletions src/AnyIterator.php
Expand Up @@ -32,27 +32,23 @@ public function __construct($list)
}

/**
* How many elements have
* @return int
* @inheritDoc
*/
public function count()
{
return count($this->list);
}

/**
* Ask the Iterator is exists more rows. Use before moveNext method.
* @return bool True if exist more rows, otherwise false
* @inheritDoc
*/
public function hasNext()
{
return ($this->curRow < $this->count());
}

/**
* Return the next row.
*
* @return Row|null
* @inheritDoc
*/
public function moveNext()
{
Expand All @@ -62,6 +58,9 @@ public function moveNext()
return $this->list[$this->curRow++];
}

/**
* @inheritDoc
*/
public function key()
{
return $this->curRow;
Expand Down
11 changes: 10 additions & 1 deletion src/Formatter/BaseFormatter.php
Expand Up @@ -13,10 +13,19 @@ abstract class BaseFormatter implements FormatterInterface
*/
protected $object;

/**
* @inheritDoc
*/
abstract public function raw();

/**
* @inheritDoc
*/
abstract public function toText();

/**
* @inheritDoc
*/
public function saveToFile($filename)
{
if (empty($filename)) {
Expand All @@ -26,7 +35,7 @@ public function saveToFile($filename)
}

/**
* $object AnyDataset|Row
* @param GenericIterator|Row $object
*/
public function __construct($object)
{
Expand Down
7 changes: 6 additions & 1 deletion src/Formatter/JsonFormatter.php
Expand Up @@ -6,12 +6,17 @@

class JsonFormatter extends BaseFormatter
{
/**
* @inheritDoc
*/
public function raw()
{
return json_decode($this->toText());
}


/**
* @inheritDoc
*/
public function toText()
{
if ($this->object instanceof GenericIterator) {
Expand Down

0 comments on commit 70e3039

Please sign in to comment.