Skip to content

Commit

Permalink
fix: Improve PHP syntax (#228)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabian Meyer <[email protected]>
  • Loading branch information
smnandre and meyfa authored Mar 30, 2024
1 parent e62e8ed commit 170cd84
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 19 deletions.
26 changes: 20 additions & 6 deletions src/Nodes/SVGNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,29 @@
*/
abstract class SVGNode
{
/** @var SVGNodeContainer $parent The parent node. */
/**
* @var SVGNodeContainer $parent The parent node.
*/
protected ?SVGNodeContainer $parent;
/** @var string[] $namespaces A map of custom namespaces to their URIs. */

/**
* @var string[] $namespaces A map of custom namespaces to their URIs.
*/
private array $namespaces;
/** @var string[] $attributes This node's set of attributes. */

/**
* @var string[] $attributes This node's set of attributes.
*/
protected array $attributes;
/** @var string[] $styles This node's set of explicit style declarations. */

/**
* @var string[] $styles This node's set of explicit style declarations.
*/
protected array $styles;
/** @var string $value This node's value */

/**
* @var string $value This node's value
*/
protected string $value;

public function __construct()
Expand Down Expand Up @@ -276,7 +290,7 @@ public function getIdAndClassPattern(): ?string
*/
public function getViewBox(): ?array
{
if ($this->getAttribute('viewBox') == null) {
if ($this->getAttribute('viewBox') === null) {
return null;
}
$attr = Str::trim($this->getAttribute('viewBox'));
Expand Down
4 changes: 3 additions & 1 deletion src/Nodes/SVGNodeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
*/
abstract class SVGNodeContainer extends SVGNode
{
/** @var SVGNode[] $children This node's child nodes. */
/**
* @var SVGNode[] $children This node's child nodes.
*/
protected array $children;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Nodes/Structures/SVGDocumentFragment.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class SVGDocumentFragment extends SVGNodeContainer
{
public const TAG_NAME = 'svg';

/** @var array $initialStyles A map of style keys to their defaults. */
/**
* @var array $initialStyles A map of style keys to their defaults.
*/
private static array $initialStyles = [
'fill' => '#000000',
'stroke' => 'none',
Expand Down
2 changes: 1 addition & 1 deletion src/Rasterization/Path/PolygonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function addPointRelative(?float $x, ?float $y): void
*/
public function addPoints(array $points): void
{
$this->points = array_merge($this->points, $points);
$this->points = [...$this->points, ...$points];

$endPoint = $this->points[count($this->points) - 1];
$this->posX = $endPoint[0];
Expand Down
3 changes: 1 addition & 2 deletions src/Rasterization/Renderers/MultiPassRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ private static function parseOpacity(?string $value): float
// https://svgwg.org/svg2-draft/render.html#ObjectAndGroupOpacityProperties
// https://drafts.csswg.org/css-color/#transparency

// null
if ($value == null) {
if ($value === null) {
return 1;
}

Expand Down
8 changes: 6 additions & 2 deletions src/Rasterization/SVGRasterizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
*/
class SVGRasterizer
{
/** @var Renderers\Renderer[] $renderers Map of shapes to renderers. */
/**
* @var Renderers\Renderer[] $renderers Map of shapes to renderers.
*/
private static $renderers;

private $fontRegistry;
Expand All @@ -44,7 +46,9 @@ class SVGRasterizer
*/
private int $height;

/** @var resource $outImage The output image as a GD resource. */
/**
* @var resource $outImage The output image as a GD resource.
*/
private $outImage;

// precomputed properties for getter methods, used often during render
Expand Down
2 changes: 1 addition & 1 deletion src/Rasterization/Transform/TransformParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class TransformParser
public static function parseTransformString(?string $input, Transform $applyTo = null): Transform
{
$transform = $applyTo ?? Transform::identity();
if ($input == null) {
if ($input === null) {
return $transform;
}

Expand Down
8 changes: 6 additions & 2 deletions src/SVG.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
*/
class SVG
{
/** @var SVGReader $reader The singleton reader used by this class. */
/**
* @var SVGReader $reader The singleton reader used by this class.
*/
private static $reader;

private static $fontRegistry;

/** @var SVGDocumentFragment $document This image's root `svg` node/tag. */
/**
* @var SVGDocumentFragment $document This image's root `svg` node/tag.
*/
private SVGDocumentFragment $document;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Utilities/Colors/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static function parseHexComponents(string $str): array
$g = hexdec($str[2] . $str[3]);
$b = hexdec($str[4] . $str[5]);
$a = $len === 8 ? hexdec($str[6] . $str[7]) : 255;
} elseif ($len === 3 || $len == 4) {
} elseif ($len === 3 || $len === 4) {
$r = hexdec($str[0] . $str[0]);
$g = hexdec($str[1] . $str[1]);
$b = hexdec($str[2] . $str[2]);
Expand Down Expand Up @@ -199,7 +199,7 @@ private static function convertHSLtoRGB(float $h, float $s, float $l): array
$s = min(max($s, 0), 1);
$l = min(max($l, 0), 1);

if ($s == 0) {
if ((float) $s === 0.0) {
// shortcut if grayscale
return [$l * 255, $l * 255, $l * 255];
}
Expand Down
4 changes: 3 additions & 1 deletion src/Writing/SVGWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
*/
class SVGWriter
{
/** @var string $outString The XML output string being written */
/**
* @var string $outString The XML output string being written
*/
private string $outString = '';

public function __construct(bool $isStandalone = true)
Expand Down

0 comments on commit 170cd84

Please sign in to comment.