Skip to content

Fix misc issues #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2021
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
4 changes: 0 additions & 4 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ jobs:
phpstan:
name: PHPStan
runs-on: Ubuntu-20.04
continue-on-error: true

steps:
- name: Checkout code
Expand Down Expand Up @@ -40,7 +39,6 @@ jobs:
php-cs-fixer:
name: PHP-CS-Fixer
runs-on: Ubuntu-20.04
continue-on-error: true

steps:
- name: Checkout code
Expand Down Expand Up @@ -73,7 +71,6 @@ jobs:
psalm:
name: Psalm
runs-on: Ubuntu-20.04
continue-on-error: true

steps:
- name: Checkout code
Expand Down Expand Up @@ -106,7 +103,6 @@ jobs:
composer-normalize:
name: Composer Normalize
runs-on: Ubuntu-20.04
continue-on-error: true

steps:
- name: Set up PHP
Expand Down
2 changes: 1 addition & 1 deletion src/Issue/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getLocalLine(): int
public function getErroredLine()
{
if (null === $this->erroredLine) {
$lines = explode(PHP_EOL, $this->node->getValue());
$lines = explode("\n", $this->node->getValue());
// We do -1 because the $lines array is zero-index and the error message is 1-index
$this->erroredLine = $lines[max(0, $this->localLine - 1)];
}
Expand Down
10 changes: 5 additions & 5 deletions src/Service/CodeNodeRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ private function warmupCache(CodeNode $node, IssueCollection $issues, string $ap
return;
}

$issues->addIssue(new Issue($node, trim($process->getErrorOutput()), 'Cache Warmup', $node->getEnvironment()->getCurrentFileName(), count(explode(PHP_EOL, $node->getValue())) - 1));
$issues->addIssue(new Issue($node, trim($process->getErrorOutput()), 'Cache Warmup', $node->getEnvironment()->getCurrentFileName(), count(explode("\n", $node->getValue())) - 1));
}

private function getFile(CodeNode $node): string
{
$contents = explode(PHP_EOL, $node->getValue());
$contents = explode("\n", $node->getValue());
$regex = match ($node->getLanguage()) {
'php' => '|^// ?([a-z1-9A-Z_\-/]+\.php)$|',
'yaml' => '|^# ?([a-z1-9A-Z_\-/]+\.yaml)$|',
Expand All @@ -94,14 +94,14 @@ private function getNodeContents(CodeNode $node): string
{
$language = $node->getLanguage();
if ('php' === $language) {
return '<?php'.PHP_EOL.$node->getValue();
return '<?php'."\n".$node->getValue();
}

if ('xml' === $language) {
$contents = explode(PHP_EOL, $node->getValue());
$contents = explode("\n", $node->getValue());
unset($contents[0]);

return implode(PHP_EOL, $contents);
return implode("\n", $contents);
}

return $node->getValue();
Expand Down
6 changes: 3 additions & 3 deletions src/Service/CodeValidator/PhpValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ private function getContents(CodeNode $node, string $language): string
}

// Allow us to use "..." as a placeholder
$contents = str_replace('...', 'null', $contents);
$contents = str_replace(['...,', '...)', '...;'], ['null,', 'null)', 'null;'], $contents);

$lines = explode(PHP_EOL, $contents);
$lines = explode("\n", $contents);
if (!str_contains($lines[0] ?? '', '<?php') && !str_contains($lines[1] ?? '', '<?php') && !str_contains($lines[2] ?? '', '<?php')) {
$contents = '<?php'.PHP_EOL.$contents;
$contents = '<?php'."\n".$contents;
}

return $contents;
Expand Down
4 changes: 2 additions & 2 deletions src/Service/LineDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public static function find(CodeNode $node): int
}

$file = sprintf('%s/%s.rst', $environment->getCurrentDirectory(), $environment->getCurrentFileName());
$contents = explode(PHP_EOL, file_get_contents($file));
$codeBlock = explode(PHP_EOL, $node->getValue());
$contents = explode("\n", file_get_contents($file));
$codeBlock = explode("\n", $node->getValue());

foreach ($contents as $i => $line) {
foreach ($codeBlock as $j => $needle) {
Expand Down