Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.4"

dependencies:
- "highest"
Expand Down Expand Up @@ -53,10 +53,8 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

dependencies:
- "lowest"
Expand Down Expand Up @@ -89,10 +87,8 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

dependencies:
- "lowest"
Expand Down Expand Up @@ -125,10 +121,8 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

dependencies:
- "lowest"
Expand Down
9 changes: 9 additions & 0 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;

return (new Configuration())
->addPathToExclude(__DIR__ . '/tests')
;
19 changes: 7 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@
}
],
"require": {
"php": ">=8.1",
"azjezz/psl": "^2.9 || ^3.2",
"cuyz/valinor": "^1.9",
"php": ">=8.4",
"cuyz/valinor": "^2.0",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"setono/html-element": "^1.0",
"symfony/options-resolver": "^4.4 || ^5.4 || ^6.0 || ^7.0 || ^8.0"
"symfony/options-resolver": "^6.4 || ^7.0 || ^8.0"
},
"require-dev": {
"infection/infection": "^0.28.1",
"php-standard-library/psalm-plugin": "^2.3",
"phpunit/phpunit": "^9.6",
"psalm/plugin-phpunit": "^0.19.5",
"setono/code-quality-pack": "^2.6",
"shipmonk/composer-dependency-analyser": "^1.8.2"
"setono/code-quality-pack": "^3.4"
},
"prefer-stable": true,
"autoload": {
Expand All @@ -40,12 +34,13 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false,
"ergebnis/composer-normalize": true,
"infection/extension-installer": true
"infection/extension-installer": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
"scripts": {
"analyse": "psalm",
"analyse": "phpstan",
"check-style": "ecs check",
"fix-style": "ecs check --fix",
"phpunit": "phpunit",
Expand Down
9 changes: 9 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
includes:
- vendor/cuyz/valinor/qa/PHPStan/valinor-phpstan-configuration.php

parameters:
level: max
paths:
- src
- tests
tmpDir: .build/phpstan
16 changes: 9 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php"
colors="true" verbose="true">
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".build/phpunit"
colors="true">
<testsuites>
<testsuite name="EditorJS Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
31 changes: 0 additions & 31 deletions psalm.xml

This file was deleted.

21 changes: 10 additions & 11 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\PHPUnit\Set\PHPUnitSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->cacheClass(FileCacheStorage::class);
$rectorConfig->cacheDirectory('./.build/rector');

$rectorConfig->paths([
return RectorConfig::configure()
->withCache('./.build/rector', FileCacheStorage::class)
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withPhpSets(php84: true)
->withAttributesSets(phpunit: true)
->withSets([
PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::PHPUNIT_110,
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81
]);
};
4 changes: 2 additions & 2 deletions src/Block/Image/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Setono\EditorJS\Block\Image;

// todo right now it doesn't support the extra data you can set on the File object (see https://github.com/editor-js/image#providing-custom-uploading-methods)
final class File
final readonly class File
{
public function __construct(public readonly string $url)
public function __construct(public string $url)
{
}
}
2 changes: 1 addition & 1 deletion src/Block/ImageBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
/**
* Returns true if the caption is not empty, i.e. $this->caption !== ''
*
* @psalm-assert-if-true non-empty-string $this->caption
* @phpstan-assert-if-true non-empty-string $this->caption
*/
public function hasCaption(): bool
{
Expand Down
4 changes: 2 additions & 2 deletions src/Block/ListBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

final class ListBlock extends Block
{
public const STYLE_ORDERED = 'ordered';
public const string STYLE_ORDERED = 'ordered';

public const STYLE_UNORDERED = 'unordered';
public const string STYLE_UNORDERED = 'unordered';

/**
* This is a helper property containing the html tag for the list (i.e. ol/ul)
Expand Down
7 changes: 5 additions & 2 deletions src/BlockRenderer/DelimiterBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ public function render(Block $block): HtmlElement
{
UnsupportedBlockException::assert($this->supports($block), $block, $this);

return (new HtmlElement($this->getOption('tag')))->withClass($this->getClassOption('class'));
$tag = $this->getOption('tag');

return new HtmlElement(is_string($tag) ? $tag : 'hr')->withClass($this->getClassOption('class'));
}

/**
* @psalm-assert-if-true DelimiterBlock $block
* @phpstan-assert-if-true DelimiterBlock $block
*/
public function supports(Block $block): bool
{
return $block instanceof DelimiterBlock;
}

#[\Override]
protected function configureOptions(OptionsResolver $optionsResolver): void
{
parent::configureOptions($optionsResolver);
Expand Down
3 changes: 2 additions & 1 deletion src/BlockRenderer/EmbedBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function render(Block $block): HtmlElement
)->withClass($this->getClassOption('containerClass'));
}

#[\Override]
protected function configureOptions(OptionsResolver $optionsResolver): void
{
parent::configureOptions($optionsResolver);
Expand All @@ -41,7 +42,7 @@ protected function configureOptions(OptionsResolver $optionsResolver): void
}

/**
* @psalm-assert-if-true EmbedBlock $block
* @phpstan-assert-if-true EmbedBlock $block
*/
public function supports(Block $block): bool
{
Expand Down
16 changes: 10 additions & 6 deletions src/BlockRenderer/GenericBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@

abstract class GenericBlockRenderer implements BlockRendererInterface
{
/** @var array<string, mixed> */
private array $options;

/**
* @param array<string, mixed> $options
*/
public function __construct(array $options = [])
{
$resolver = new OptionsResolver();
$this->configureOptions($resolver);

try {
$this->options = $resolver->resolve($options);
/** @var array<string, mixed> $resolvedOptions */
$resolvedOptions = $resolver->resolve($options);
$this->options = $resolvedOptions;
} catch (ExceptionInterface $e) {
throw new OptionsResolverException($e, $this);
}
Expand All @@ -34,9 +40,6 @@
;
}

/**
* @psalm-assert-if-true mixed $this->options[$option]
*/
protected function hasOption(string $option): bool
{
return isset($this->options[$option]);
Expand All @@ -45,7 +48,7 @@
protected function getOption(string $option): mixed
{
if (!$this->hasOption($option)) {
throw new UndefinedOptionException($option, array_keys($this->options));

Check warning on line 51 in src/BlockRenderer/GenericBlockRenderer.php

View workflow job for this annotation

GitHub Actions / Mutation tests (8.4, highest)

Escaped Mutant for Mutator "UnwrapArrayKeys": @@ @@ protected function getOption(string $option): mixed { if (!$this->hasOption($option)) { - throw new UndefinedOptionException($option, array_keys($this->options)); + throw new UndefinedOptionException($option, $this->options); } return $this->options[$option];
}

return $this->options[$option];
Expand All @@ -63,7 +66,8 @@
return '';
}

/** @psalm-suppress MixedArgument */
return sprintf('%s%s', $this->getOption('classPrefix'), $option);
$prefix = $this->getOption('classPrefix');

return sprintf('%s%s', is_string($prefix) ? $prefix : '', $option);
}
}
4 changes: 2 additions & 2 deletions src/BlockRenderer/HeaderBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public function render(Block $block): HtmlElement
{
UnsupportedBlockException::assert($this->supports($block), $block, $this);

return (new HtmlElement(sprintf('h%d', $block->level), $block->text))
return new HtmlElement(sprintf('h%d', $block->level), $block->text)
->withClass($this->getClassOption('class'))
;
}

/**
* @psalm-assert-if-true HeaderBlock $block
* @phpstan-assert-if-true HeaderBlock $block
*/
public function supports(Block $block): bool
{
Expand Down
3 changes: 2 additions & 1 deletion src/BlockRenderer/ImageBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function render(Block $block): HtmlElement
return $container;
}

#[\Override]
protected function configureOptions(OptionsResolver $optionsResolver): void
{
parent::configureOptions($optionsResolver);
Expand All @@ -70,7 +71,7 @@ protected function configureOptions(OptionsResolver $optionsResolver): void
}

/**
* @psalm-assert-if-true ImageBlock $block
* @phpstan-assert-if-true ImageBlock $block
*/
public function supports(Block $block): bool
{
Expand Down
7 changes: 4 additions & 3 deletions src/BlockRenderer/ListBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ public function render(Block $block): HtmlElement
{
UnsupportedBlockException::assert($this->supports($block), $block, $this);

return (new HtmlElement($block->tag, ...array_map(
return new HtmlElement($block->tag, ...array_map(
fn (string $item) => HtmlElement::li($item)->withClass($this->getClassOption('itemClass')),
$block->items,
)))
))
->withClass($this->getClassOption('class'))
;
}

#[\Override]
protected function configureOptions(OptionsResolver $optionsResolver): void
{
parent::configureOptions($optionsResolver);
Expand All @@ -37,7 +38,7 @@ protected function configureOptions(OptionsResolver $optionsResolver): void
}

/**
* @psalm-assert-if-true ListBlock $block
* @phpstan-assert-if-true ListBlock $block
*/
public function supports(Block $block): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/BlockRenderer/ParagraphBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function render(Block $block): HtmlElement
}

/**
* @psalm-assert-if-true ParagraphBlock $block
* @phpstan-assert-if-true ParagraphBlock $block
*/
public function supports(Block $block): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/BlockRenderer/QuoteBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function render(Block $block): HtmlElement
}

/**
* @psalm-assert-if-true QuoteBlock $block
* @phpstan-assert-if-true QuoteBlock $block
*/
public function supports(Block $block): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/BlockRenderer/RawBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function render(Block $block): HtmlElement
}

/**
* @psalm-assert-if-true RawBlock $block
* @phpstan-assert-if-true RawBlock $block
*/
public function supports(Block $block): bool
{
Expand Down
Loading
Loading