Skip to content

Commit

Permalink
Merge pull request #18 from Hi-Folks/feat/phpstan
Browse files Browse the repository at this point in the history
Adding Static Code Analysis (PHPstan)
  • Loading branch information
roberto-butti authored Jan 24, 2024
2 parents f018b32 + c9e867f commit 93c6111
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.0.11 - WIP
- Adding PHPstan for static code analysis

## 1.0.10 - 24th January 2024
- Fixing and updating styles for Aside blok

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This command encompasses:

- PER Coding Standard checks employing Laravel Pint.
- Executing some RectoryPHP checks, like the usage of PHP updated syntax (at least 8.1), the type declaration, early return, and dead code. For more info check the `rector.php` file in the root of the project.
- (WIP) PHPStan analysis.
- PHPStan analysis.
- (WIP) Execution of all tests from the `./tests/*` directory using PestPHP.

We recommend running `composer all-check` before committing and creating a pull request.
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License (MIT)

Ibis original project: Copyright (c) Mohamed Said <[email protected]>
Ibis Next project: Copyright (c) Roberto Butti
**Ibis Next** project: Copyright (c) Roberto Butti
Ibis original project: Copyright (c) Mohamed Said

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"require-dev": {
"laravel/pint": "^1.2",
"phpstan/phpstan": "^1.10",
"rector/rector": "^0.19.2",
"symfony/var-dumper": "^6.0|^7.0"
},
Expand All @@ -60,9 +61,13 @@
"refactor-review": [
"rector process src --dry-run"
],
"code-analysis": [
"vendor/bin/phpstan analyse"
],
"all-check": [
"@refactor-review",
"@csfix"
"@csfix",
"@code-analysis"
]
},
"scripts-descriptions": {
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method League\\\\CommonMark\\\\Node\\\\Node\\:\\:getTitle\\(\\)\\.$#"
count: 2
path: src/Markdown/Extensions/AsideRenderer.php

-
message: "#^Call to an undefined method League\\\\CommonMark\\\\Node\\\\Node\\:\\:getType\\(\\)\\.$#"
count: 1
path: src/Markdown/Extensions/AsideRenderer.php
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- phpstan-baseline.neon
parameters:
level: 5
paths:
- src
23 changes: 12 additions & 11 deletions src/Commands/BaseBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Ibis\Commands;

use Ibis\Config;
use Ibis\Markdown\Extensions\Aside;
use Ibis\Markdown\Extensions\AsideExtension;
use Ibis\Markdown\Extensions\AsideRenderer;
use SplFileInfo;

use Illuminate\Filesystem\Filesystem;
Expand Down Expand Up @@ -80,6 +82,7 @@ protected function buildHtml(string $path, array $config): Collection
$environment->addRenderer(IndentedCode::class, new IndentedCodeRenderer([
'html', 'php', 'js', 'bash', 'json'
]));
$environment->addRenderer(Aside::class, new AsideRenderer());

if (is_callable($config['configure_commonmark'])) {
call_user_func($config['configure_commonmark'], $environment);
Expand All @@ -92,30 +95,28 @@ protected function buildHtml(string $path, array $config): Collection

$chapter = collect([]);
if ($file->getExtension() != 'md') {
$chapter["mdfile"] = $file->getFilename();
$chapter["frontmatter"] = false;
$chapter["html"] = "";
$chapter->put("mdfile", $file->getFilename());
$chapter->put("frontmatter", false);
$chapter->put("html", "");
return $chapter;
}

$markdown = $this->disk->get(
$file->getPathname()
);


//$chapter = collect([]);
$convertedMarkdown = $converter->convert($markdown);
$chapter["mdfile"] = $file->getFilename();
$chapter["frontmatter"] = false;
$chapter->put("mdfile", $file->getFilename());
$chapter->put("frontmatter", false);
if ($convertedMarkdown instanceof RenderedContentWithFrontMatter) {
$chapter["frontmatter"] = $convertedMarkdown->getFrontMatter();
$chapter->put("frontmatter", $convertedMarkdown->getFrontMatter());
}

$chapter["html"] = $this->prepareHtmlForEbook(
$chapter->put("html", $this->prepareHtmlForEbook(
$convertedMarkdown->getContent(),
$i + 1,
Arr::get($config, "breakLevel", 2)
);
));


return $chapter;
Expand All @@ -126,7 +127,7 @@ protected function buildHtml(string $path, array $config): Collection

/**
* @param $file
* @return string|string[]
* @param int $breakLevel
*/
protected function prepareHtmlForEbook(string $html, $file, $breakLevel = 2): string
{
Expand Down
8 changes: 3 additions & 5 deletions src/Commands/BuildEpubCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Ibis\Commands;

use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

Expand Down Expand Up @@ -83,11 +84,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}



/**
* @param string $theme
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
* @throws \Mpdf\MpdfException
* @throws FileNotFoundException
*/
protected function buildEpub(Collection $chapters, array $config, string $currentPath): bool
{
Expand Down Expand Up @@ -153,7 +151,7 @@ protected function buildEpub(Collection $chapters, array $config, string $curren
$this->output->writeln('<fg=yellow>==></> ❇️ ' . $chapter["mdfile"] . ' ...');

$book->addChapter(
chapterName: Arr::get($chapter, "frontmatter.title", "Chapter " . $key + 1),
chapterName: Arr::get($chapter, "frontmatter.title", "Chapter " . ($key + 1)),
fileName: "Chapter" . $key . ".html",
chapterData: $content_start . $chapter["html"] . $content_end,
externalReferences: EPub::EXTERNAL_REF_ADD
Expand Down
2 changes: 1 addition & 1 deletion src/Markdown/Extensions/Aside.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(private $type = self::TYPE_NOTE, $title = "")
parent::__construct();
}

public function getType()
public function getType(): string
{
return $this->type;
}
Expand Down
1 change: 1 addition & 0 deletions src/Markdown/Extensions/AsideRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer)
Aside::assertInstanceOf($node);

$attrs = $node->data->getData('attributes');
//dd($node);
$contents = $childRenderer->renderNodes($node->children());
$blockQuoteContent = new HtmlElement('div', $attrs->export(), $contents);
$blockQuoteTitle = "";
Expand Down

0 comments on commit 93c6111

Please sign in to comment.