Skip to content

Commit

Permalink
Laravel 9 support (#22)
Browse files Browse the repository at this point in the history
* Support Laravel 9
* Drop support for Laravel < 8
* Drop support for `master` branch. `main` is used as default branch
  • Loading branch information
reliq committed Feb 28, 2022
1 parent d94d5f8 commit 330be9d
Show file tree
Hide file tree
Showing 37 changed files with 318 additions and 196 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ jobs:
strategy:
max-parallel: 10
matrix:
laravel-version: ['^7.0', '^8.0']
laravel-version: ['^8.0', '^9.0']
preference: ['stable']
php-version: ['7.4', '8.0']
exclude:
- laravel-version: ^7.0
- laravel-version: ^8.0
php-version: 8.0
- laravel-version: ^9.0
php-version: 7.4
name: Laravel ${{ matrix.laravel-version }} (${{ matrix.preference }}) on PHP ${{ matrix.php-version }}
steps:
- name: Checkout
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
"require": {
"php": "^7.4 || ^8.0",
"ext-json": "*",
"illuminate/support": "7 - 8",
"league/commonmark": "^1.5",
"illuminate/support": "8 - 9",
"league/commonmark": "^2.2",
"monolog/monolog": "1.24 - 2",
"nesbot/carbon": "^2.0",
"reliqarts/laravel-common": "^5.0",
"symfony/browser-kit": "^4.3",
"symfony/process": "4 - 5",
"symfony/yaml": "^4.3"
"reliqarts/laravel-common": ">=5.0",
"symfony/browser-kit": ">=4.3",
"symfony/process": ">=4.0",
"symfony/yaml": ">=4.3"
},
"require-dev": {
"orchestra/testbench-browser-kit": "4 - 6",
"orchestra/testbench-browser-kit": "4 - 7",
"phpunit/phpunit": "^9.3",
"phpro/grumphp": "^1.0",
"phpspec/prophecy-phpunit": "^2.0",
"symplify/easy-coding-standard": "^8.2"
"symplify/easy-coding-standard": ">=8.2"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 7 additions & 6 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();

$parameters->set('line_ending', "\n");
$containerConfigurator->import(SetList::CLEAN_CODE);
$containerConfigurator->import(SetList::PSR_12);

$parameters->set('paths', [__DIR__ . '/src', __DIR__ . '/tests']);

$parameters->set('sets', ['clean-code', 'psr12']);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::LINE_ENDING, "\n");
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
};
4 changes: 2 additions & 2 deletions src/Console/Command/Publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace ReliqArts\Docweaver\Console\Command;

use Carbon\Carbon;
use ReliqArts\Docweaver\Exception\InvalidDirectory;
use ReliqArts\Docweaver\Exception\InvalidDirectoryException;

class Publish extends SingleProductCommand
{
Expand All @@ -30,7 +30,7 @@ class Publish extends SingleProductCommand
/**
* Execute the console command.
*
* @throws InvalidDirectory
* @throws InvalidDirectoryException
*/
public function handle(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface ConfigProvider
*
* @param bool $absolute whether to return full
*/
public function getDocumentationDirectory($absolute = false): string;
public function getDocumentationDirectory(bool $absolute = false): string;

/**
* Get route config.
Expand Down
4 changes: 2 additions & 2 deletions src/Contract/Documentation/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Illuminate\Console\Command;
use ReliqArts\Docweaver\Contract\Publisher as BasePublisher;
use ReliqArts\Docweaver\Exception\InvalidDirectory;
use ReliqArts\Docweaver\Exception\InvalidDirectoryException;
use ReliqArts\Docweaver\Result;

interface Publisher extends BasePublisher
Expand All @@ -18,7 +18,7 @@ interface Publisher extends BasePublisher
* @param string $source Git Repository
* @param Command $callingCommand Calling Command
*
* @throws InvalidDirectory
* @throws InvalidDirectoryException
*/
public function publish(string $productName, string $source, Command &$callingCommand = null): Result;

Expand Down
2 changes: 1 addition & 1 deletion src/Contract/MarkdownParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
interface MarkdownParser
{
/**
* Convert markdown text to HTML text.
* Convert Markdown to HTML text.
*/
public function parse(string $text): string;
}
4 changes: 4 additions & 0 deletions src/Contract/ProcessHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

namespace ReliqArts\Docweaver\Contract;

use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Process;

interface ProcessHelper
{
/**
* @throws LogicException
*/
public function createProcess(
array $command,
string $cwd = null,
Expand Down
8 changes: 6 additions & 2 deletions src/Contract/Product/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@

namespace ReliqArts\Docweaver\Contract\Product;

use Exception;
use LogicException;
use ReliqArts\Docweaver\Contract\Publisher as BasePublisher;
use ReliqArts\Docweaver\Exception\Product\PublicationFailed;
use ReliqArts\Docweaver\Model\Product;
use ReliqArts\Docweaver\Result;
use Symfony\Component\Process\Exception\ProcessFailedException;

interface Publisher extends BasePublisher
{
/**
* Publish product documentation (all versions).
*
* @throws PublicationFailed
* @throws Exception
*/
public function publish(Product $product, string $source): Result;

/**
* Update product documentation (all versions).
*
* @throws ProcessFailedException|LogicException
*/
public function update(Product $product): Result;
}
5 changes: 3 additions & 2 deletions src/Contract/VcsCommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ReliqArts\Docweaver\Contract;

use LogicException;
use Symfony\Component\Process\Exception\ProcessFailedException;

interface VcsCommandRunner
Expand All @@ -16,12 +17,12 @@ public function clone(string $source, string $branch, string $workingDirectory):
public function pull(string $workingDirectory): void;

/**
* @throws ProcessFailedException
* @throws ProcessFailedException|LogicException
*/
public function listTags(string $workingDirectory): array;

/**
* @throws ProcessFailedException
* @throws ProcessFailedException|LogicException
*/
public function getRemoteUrl(string $workingDirectory, ?string $remoteName = null): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
/**
* {@inheritdoc}
*/
final class BadImplementation extends Exception
final class BadImplementationException extends Exception
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ReliqArts\Docweaver\Exception;

final class DirectoryNotWritable extends InvalidDirectory
final class DirectoryNotWritableException extends InvalidDirectoryException
{
protected const MESSAGE_TEMPLATE = 'Directory `%s` is not writable.';
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use ReliqArts\Docweaver\Contract\Exception as ExceptionContract;

class InvalidDirectory extends Exception
class InvalidDirectoryException extends Exception
{
protected const MESSAGE_TEMPLATE = 'Invalid directory: `%s`.';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use ReliqArts\Docweaver\Contract\Exception as ExceptionContract;

final class ParsingFailed extends Exception
final class ParsingFailedException extends Exception
{
private const CODE = 1004;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use ReliqArts\Docweaver\Contract\Exception;
use ReliqArts\Docweaver\Model\Product;

final class AssetPublicationFailed extends PublicationFailed
final class AssetPublicationFailedException extends PublicationFailedException
{
private const CODE = 8002;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace ReliqArts\Docweaver\Exception\Product;

use ReliqArts\Docweaver\Contract\Exception;
use ReliqArts\Docweaver\Exception\InvalidDirectory;
use ReliqArts\Docweaver\Exception\InvalidDirectoryException;

final class InvalidAssetDirectory extends InvalidDirectory
final class InvalidAssetDirectoryException extends InvalidDirectoryException
{
private const CODE = 4003;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use ReliqArts\Docweaver\Contract\Exception as ExceptionContract;
use ReliqArts\Docweaver\Exception\Exception;
use ReliqArts\Docweaver\Model\Product;
use Throwable;

class PublicationFailed extends Exception
class PublicationFailedException extends Exception
{
private const CODE = 8001;

Expand All @@ -20,9 +21,13 @@ class PublicationFailed extends Exception
public static function forProductVersion(
Product $product,
string $version,
Exception $previous = null
Throwable $previous = null
): ExceptionContract {
$message = sprintf('Failed to publish version `%s` of product `%s`.', $version, $product->getName());
if ($previous !== null) {
$message .= sprintf(' %s', $previous->getMessage());
}

$self = new self($message, self::CODE, $previous);
$self->product = $product;

Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ProductMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use ReliqArts\Docweaver\Contract\Filesystem;
use ReliqArts\Docweaver\Contract\Product\Maker;
use ReliqArts\Docweaver\Contract\YamlHelper;
use ReliqArts\Docweaver\Exception\InvalidDirectory;
use ReliqArts\Docweaver\Exception\InvalidDirectoryException;
use ReliqArts\Docweaver\Model\Product;

final class ProductMaker implements Maker
Expand Down Expand Up @@ -41,7 +41,7 @@ public function __construct(
public function create(string $directory): Product
{
if (!$this->filesystem->isDirectory($directory)) {
throw InvalidDirectory::forDirectory($directory);
throw InvalidDirectoryException::forDirectory($directory);
}

$product = new Product(
Expand Down
4 changes: 4 additions & 0 deletions src/Helper/ProcessHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
namespace ReliqArts\Docweaver\Helper;

use ReliqArts\Docweaver\Contract\ProcessHelper as ProcessHelperContract;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Process;

final class ProcessHelper implements ProcessHelperContract
{
/**
* @throws LogicException
*/
public function createProcess(
array $command,
string $cwd = null,
Expand Down
18 changes: 9 additions & 9 deletions src/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
use ReliqArts\Docweaver\Contract\FileHelper;
use ReliqArts\Docweaver\Contract\Filesystem;
use ReliqArts\Docweaver\Contract\YamlHelper;
use ReliqArts\Docweaver\Exception\ParsingFailed;
use ReliqArts\Docweaver\Exception\Product\AssetPublicationFailed;
use ReliqArts\Docweaver\Exception\Product\InvalidAssetDirectory;
use ReliqArts\Docweaver\Exception\ParsingFailedException;
use ReliqArts\Docweaver\Exception\Product\AssetPublicationFailedException;
use ReliqArts\Docweaver\Exception\Product\InvalidAssetDirectoryException;
use RuntimeException;

/**
* A documented product.
*/
class Product implements Arrayable, Jsonable
{
public const VERSION_MASTER = 'master';
public const VERSION_MAIN = 'main';
public const VERSION_UNKNOWN = 'unknown';

private const ASSET_URL_PLACEHOLDER_1 = '{{docs}}';
Expand Down Expand Up @@ -209,11 +209,11 @@ public function publishAssets(string $version): void
$imageDirectory = sprintf('%s/%s/images', $this->directory, $version);

if (!$this->filesystem->isDirectory($imageDirectory)) {
throw InvalidAssetDirectory::forDirectory($imageDirectory);
throw InvalidAssetDirectoryException::forDirectory($imageDirectory);
}

if (!$this->filesystem->copyDirectory($imageDirectory, sprintf('%s/images', $storagePath))) {
throw AssetPublicationFailed::forProductAssetsOfType($this, 'image');
throw AssetPublicationFailedException::forProductAssetsOfType($this, 'image');
}
}

Expand Down Expand Up @@ -246,9 +246,9 @@ public function toJson($options = 0): string
return json_encode($this->toArray(), JSON_THROW_ON_ERROR, 512);
}

public function getMasterDirectory(): string
public function getMainDirectory(): string
{
return sprintf('%s/%s', $this->getDirectory(), self::VERSION_MASTER);
return sprintf('%s/%s', $this->getDirectory(), self::VERSION_MAIN);
}

/**
Expand Down Expand Up @@ -305,7 +305,7 @@ private function loadMeta(?string $version = null): void
$exception->getMessage()
);

throw ParsingFailed::forFile($metaFile)->withMessage($message);
throw ParsingFailedException::forFile($metaFile)->withMessage($message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Service/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(Config $config)
*
* @param bool $absolute whether to return full
*/
public function getDocumentationDirectory($absolute = false): string
public function getDocumentationDirectory(bool $absolute = false): string
{
$path = $this->get(self::KEY_STORAGE_DIRECTORY);

Expand Down
6 changes: 3 additions & 3 deletions src/Service/Documentation/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use ReliqArts\Docweaver\Contract\Documentation\Provider as ProviderContract;
use ReliqArts\Docweaver\Contract\Filesystem;
use ReliqArts\Docweaver\Contract\MarkdownParser;
use ReliqArts\Docweaver\Exception\BadImplementation;
use ReliqArts\Docweaver\Exception\BadImplementationException;
use ReliqArts\Docweaver\Model\Product;

final class Provider implements ProviderContract
Expand Down Expand Up @@ -53,7 +53,7 @@ final class Provider implements ProviderContract
/**
* Create a new documentation instance.
*
* @throws BadImplementation
* @throws BadImplementationException
*/
public function __construct(
Filesystem $filesystem,
Expand All @@ -70,7 +70,7 @@ public function __construct(
$documentationDirectoryAbsolutePath = base_path($documentationDirectory);

if (!$this->filesystem->isDirectory($documentationDirectoryAbsolutePath)) {
throw new BadImplementation(sprintf('Documentation resource directory `%s` does not exist.', $documentationDirectory));
throw new BadImplementationException(sprintf('Documentation resource directory `%s` does not exist.', $documentationDirectory));
}
}

Expand Down

0 comments on commit 330be9d

Please sign in to comment.