Skip to content

Commit

Permalink
Merge pull request #17 from RonasIT/dpankratov/version-update
Browse files Browse the repository at this point in the history
Dpankratov/version update
  • Loading branch information
DenTray authored Nov 22, 2021
2 parents 4316647 + f56ecd2 commit ecbfdc3
Show file tree
Hide file tree
Showing 40 changed files with 369 additions and 867 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}
],
"require": {
"php": ">=7.0",
"laravel/framework": ">=5.2.0",
"php": ">=7.1",
"laravel/framework": ">=5.4.0",
"guzzlehttp/guzzle": "~6.0",
"tymon/jwt-auth": "0.5.* || 1.0.*",
"minime/annotations": "~3.0",
Expand Down
18 changes: 10 additions & 8 deletions src/BaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

use Illuminate\Support\Arr;
use Illuminate\Foundation\Http\FormRequest;
use RonasIT\Support\AutoDoc\Traits\AutoDocRequestTrait;

class BaseRequest extends FormRequest
{
use AutoDocRequestTrait;

public function authorize()
public function authorize(): bool
{
return true;
}

public function rules(): array
{
return [];
}

/**
* @param array|string $keys
* @param mixed $default
Expand All @@ -25,7 +27,7 @@ public function authorize()
* @return array;
*/

public function onlyValidated($keys = null, $default = null)
public function onlyValidated($keys = null, $default = null): array
{
$rules = array_keys($this->rules());

Expand All @@ -40,7 +42,7 @@ public function onlyValidated($keys = null, $default = null)
return $validatedFields;
}

protected function filterOnlyValidated($fields, $validation)
protected function filterOnlyValidated($fields, $validation): array
{
$result = [];

Expand Down Expand Up @@ -72,12 +74,12 @@ protected function processNestedRule($validatedKeys, $validatedItem)
}, $validatedItem);
}

protected function isNotNestedRule($validatedKeys)
protected function isNotNestedRule($validatedKeys): bool
{
return is_integer($validatedKeys);
}

private function sortByStrlen(array &$array)
private function sortByStrlen(array &$array): void
{
$collection = collect($array)->sortBy(function ($string) {
return strlen($string);
Expand Down
3 changes: 1 addition & 2 deletions src/Exceptions/CircularRelationsFoundedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class CircularRelationsFoundedException extends EntityCreateException
{

}
}
3 changes: 1 addition & 2 deletions src/Exceptions/ClassAlreadyExistsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class ClassAlreadyExistsException extends EntityCreateException
{

}
}
3 changes: 1 addition & 2 deletions src/Exceptions/ClassNotExistsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class ClassNotExistsException extends EntityCreateException
{

}
}
3 changes: 1 addition & 2 deletions src/Exceptions/EntityCreateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class EntityCreateException extends Exception
{

}
}
3 changes: 1 addition & 2 deletions src/Exceptions/IncorrectCSVFileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class IncorrectCSVFileException extends EntityCreateException
{

}
}
3 changes: 1 addition & 2 deletions src/Exceptions/IncorrectImportFileException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class IncorrectImportFileException extends Exception
{

}
}
3 changes: 1 addition & 2 deletions src/Exceptions/IncorrectImportLineException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class IncorrectImportLineException extends Exception
{

}
}
3 changes: 1 addition & 2 deletions src/Exceptions/InvalidModelException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class InvalidModelException extends Exception
{

}
}
3 changes: 1 addition & 2 deletions src/Exceptions/ModelFactoryNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class ModelFactoryNotFound extends EntityCreateException
{

}
}
3 changes: 1 addition & 2 deletions src/Exceptions/ModelFactoryNotFoundedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class ModelFactoryNotFoundedException extends EntityCreateException
{

}
}
3 changes: 1 addition & 2 deletions src/Exceptions/UnknownRequestMethodException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class UnknownRequestMethodException extends EntityCreateException
{

}
}
11 changes: 7 additions & 4 deletions src/Exporters/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace RonasIT\Support\Exporters;

use Illuminate\Support\Arr;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Storage;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
Expand Down Expand Up @@ -31,12 +32,14 @@ public function setQuery($query): self
return $this;
}

public function setDisk($disk)
public function setDisk($disk): self
{
$this->disk = $disk;

return $this;
}

public function setFileName($fileName): self
public function setFileName(string $fileName): self
{
$this->fileName = $fileName;

Expand All @@ -48,7 +51,7 @@ public function setFileName($fileName): self
*
* @return $this
*/
public function setType($type): self
public function setType(string $type): self
{
$this->type = $type;

Expand All @@ -64,7 +67,7 @@ public function export(): string
return Storage::disk($this->disk)->path($filename);
}

public function query()
public function query(): Builder
{
return $this->query;
}
Expand Down
44 changes: 23 additions & 21 deletions src/Importers/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,28 @@ class Importer
];
protected $mandatoryFields = [];

public function setInput($input)
public function setInput($input): self
{
$this->input = $input;

return $this;
}

public function setService($service)
public function setService($service): self
{
$this->service = $service;

return $this;
}

public function setExporter($exporter)
public function setExporter($exporter): self
{
$this->exporter = app($exporter);

return $this;
}

public function import()
public function import(): array
{
$this->prepare();

Expand All @@ -65,12 +65,14 @@ public function import()
return $this->report;
}

public function prepare()
public function prepare(): self
{
$this->iterator = new CsvIterator($this->input);

return $this;
}

protected function markAllLines()
protected function markAllLines(): void
{
$isFilterLine = true;

Expand Down Expand Up @@ -102,13 +104,13 @@ protected function markAllLines()
}
}

protected function resolve()
protected function resolve(): void
{
$this->createAllMarked();
$this->updateAllMarked();
}

protected function prepareFields($line)
protected function prepareFields(array $line): array
{
return array_map(function ($field) {
$field = strtolower($field);
Expand All @@ -117,7 +119,7 @@ protected function prepareFields($line)
}, $line);
}

protected function prepareLine($line)
protected function prepareLine(array $line): array
{
if (empty($line['id'])) {
$line['id'] = null;
Expand All @@ -130,7 +132,7 @@ protected function prepareLine($line)
return $line;
}

protected function markForCreate($line)
protected function markForCreate(array $line): void
{
if (!$this->isValidForCreation($line)) {
return;
Expand All @@ -139,7 +141,7 @@ protected function markForCreate($line)
$this->items[self::ITEMS_TO_CREATE][] = $line;
}

protected function isValidForCreation($line)
protected function isValidForCreation(array $line): bool
{
if (empty($line['id'])) {
return true;
Expand All @@ -148,14 +150,14 @@ protected function isValidForCreation($line)
return !$this->service->withTrashed()->exists(['id' => $line['id']]);
}

protected function markForUpdate($line)
protected function markForUpdate(array $line): void
{
if ($this->isValidForUpdating($line)) {
$this->items[self::ITEMS_TO_UPDATE][$line['id']] = $line;
}
}

protected function isValidForUpdating($line)
protected function isValidForUpdating(array $line): bool
{
if (empty($line['id']) || in_array($line, $this->items[self::ITEMS_TO_UPDATE])) {
return false;
Expand All @@ -166,19 +168,19 @@ protected function isValidForUpdating($line)
return !empty($diff);
}

protected function addError($error)
protected function addError(string $error): void
{
$this->report['errors'][] = $this->formatError($error);
}

protected function formatError($error)
protected function formatError(string $error): string
{
$lineNumber = $this->iterator->key() + 1;

return "Line {$lineNumber}: {$error}";
}

protected function validateDuplicatingOfId($item)
protected function validateDuplicatingOfId(array $item): bool
{
if (empty($item['id'])) {
return false;
Expand All @@ -189,7 +191,7 @@ protected function validateDuplicatingOfId($item)
]);
}

protected function createAllMarked()
protected function createAllMarked(): void
{
foreach ($this->items[self::ITEMS_TO_CREATE] as $item) {
$this->service->create($item);
Expand All @@ -198,7 +200,7 @@ protected function createAllMarked()
}
}

protected function updateAllMarked()
protected function updateAllMarked(): void
{
foreach ($this->items[self::ITEMS_TO_UPDATE] as $id => $item) {
$this->service->update(['id' => $id], $item);
Expand All @@ -207,7 +209,7 @@ protected function updateAllMarked()
}
}

protected function getDiff($item)
protected function getDiff(array $item): array
{
$itemFromDB = $this->service->first(['id' => $item['id']]);

Expand All @@ -217,7 +219,7 @@ protected function getDiff($item)
return array_diff($exportedLine, $importedLine);
}

protected function validateHeader()
protected function validateHeader(): void
{
$line = $this->iterator->current();

Expand All @@ -237,4 +239,4 @@ protected function validateHeader()
throw new IncorrectImportFileException($message);
}
}
}
}
Loading

0 comments on commit ecbfdc3

Please sign in to comment.