Skip to content

Commit

Permalink
Small code refactoring. Constructor property promotion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex K committed Dec 1, 2023
1 parent 7a8dd80 commit 39f54e1
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 87 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"require": {
"php": "^8.0",
"php": ">=8.1",
"symfony/process": "^5.0|^6.0",
"spatie/temporary-directory": "^2.0"
},
Expand Down
20 changes: 6 additions & 14 deletions src/Area.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
<?php


namespace RandomState\Camelot;


class Area
{
protected int $xTopLeft;
protected int $yTopLeft;
protected int $xBottomRight;
protected int $yBottomRight;

public function __construct(int $xTopLeft, int $yTopLeft, int $xBottomRight, int $yBottomRight)
{
$this->xTopLeft = $xTopLeft;
$this->yTopLeft = $yTopLeft;
$this->xBottomRight = $xBottomRight;
$this->yBottomRight = $yBottomRight;
}
public function __construct(
protected int $xTopLeft,
protected int $yTopLeft,
protected int $xBottomRight,
protected int $yBottomRight,
) {}

public function xTopLeft(): int
{
Expand Down
2 changes: 0 additions & 2 deletions src/Areas.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace RandomState\Camelot;


class Areas
{
protected array $areas = [];
Expand Down
55 changes: 0 additions & 55 deletions src/Camelot.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace RandomState\Camelot;


use RandomState\Camelot\Exceptions\BackgroundLinesNotSupportedException;
use RandomState\Camelot\Exceptions\ColumnSeparatorsNotSupportedException;
use RandomState\Camelot\Exceptions\PdfEncryptedException;
Expand All @@ -17,96 +15,44 @@ class Camelot

/**
* lattice | stream
*
* @var string
*/
protected string $mode;

/**
* csv | json | excel | html | sqlite
*
* @var string
*/
protected string $format = 'csv';

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

/**
* @var string
*/
protected string $pages = '';

/**
* @var string
*/
protected string $password = '';

/**
* @var string
*/
protected string $processBackgroundLines = '';

/**
* @var string
*/
protected string $plot = '';

/**
* @var Areas|null
*/
protected ?Areas $areas = null;

/**
* @var Areas|null
*/
protected ?Areas $regions = null;

/**
* @var array
*/
protected array $columnSeparators = [];

/**
* @var bool
*/
protected bool $splitAlongSeparators = false;

/**
* @var bool
*/
protected bool $flagSize = false;

/**
* @var string
*/
protected string $unwantedCharacters = '';

/**
* @var int|null
*/
protected ?int $edgeTolerance = null;

/**
* @var int|null
*/
protected ?int $rowTolerance = null;

/**
* @var int|null
*/
protected ?int $lineScale = null;

/**
* @var array
*/
protected array $textShift = [];

/**
* @var array
*/
protected array $copyTextDirections = [];

public function __construct(string $path, ?string $mode = null)
Expand Down Expand Up @@ -368,5 +314,4 @@ public function copyTextSpanningCells(...$directions): self

return $this;
}

}
4 changes: 1 addition & 3 deletions src/Exceptions/BackgroundLinesNotSupportedException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace RandomState\Camelot\Exceptions;


use RandomState\Camelot\Camelot;

class BackgroundLinesNotSupportedException extends NotSupportedException
Expand All @@ -17,7 +15,7 @@ protected function validModes(): array

protected function featureName(): string
{
return "processing background lines";
return 'processing background lines';
}

}
5 changes: 1 addition & 4 deletions src/Exceptions/ColumnSeparatorsNotSupportedException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace RandomState\Camelot\Exceptions;


use RandomState\Camelot\Camelot;

class ColumnSeparatorsNotSupportedException extends NotSupportedException
Expand All @@ -17,7 +15,6 @@ protected function validModes(): array

protected function featureName(): string
{
return "column separators";
return 'column separators';
}

}
6 changes: 3 additions & 3 deletions src/Exceptions/NotSupportedException.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?php


namespace RandomState\Camelot\Exceptions;


abstract class NotSupportedException extends \Exception
{
public function __construct(string $mode)
{
parent::__construct("Processing mode '$mode' does not support ". $this->featureName() . ". It can be used with ". $this->validModesString().".");
parent::__construct(sprintf('Processing mode "%s" does not support "%s". It can be used with "%s"', $mode, $this->featureName(), $this->validModesString()));
}

private function validModesString(): string
Expand All @@ -18,6 +16,8 @@ private function validModesString(): string

return count($validModes) > 1 ? $modes . ' modes' : $modes . ' mode';
}

abstract protected function validModes(): array;

abstract protected function featureName(): string;
}
6 changes: 1 addition & 5 deletions src/Exceptions/PdfEncryptedException.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<?php


namespace RandomState\Camelot\Exceptions;


use Throwable;

class PdfEncryptedException extends \Exception
{
public function __construct(string $filePath)
{
parent::__construct("The PDF $filePath is encrypted and cannot be read without a password. Supply a password with \$camelot->password('my_password').");
parent::__construct(sprintf('The PDF "%s" is encrypted and cannot be read without a password. Supply a password with $camelot->password(\'my_password\').', $filePath));
}
}

0 comments on commit 39f54e1

Please sign in to comment.