-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d41f846
commit 4e6596b
Showing
9 changed files
with
135 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Imanghafoori\LaravelMicroscope\Checks; | ||
|
||
use Exception; | ||
use Imanghafoori\LaravelMicroscope\Check; | ||
use Imanghafoori\LaravelMicroscope\ErrorReporters\ErrorPrinter; | ||
use Imanghafoori\LaravelMicroscope\FileReaders\FilePath; | ||
use Imanghafoori\TokenAnalyzer\Refactor; | ||
use Imanghafoori\TokenAnalyzer\SyntaxNormalizer; | ||
|
||
class CheckRubySyntax implements Check | ||
{ | ||
public static function check($tokens, $absFilePath) | ||
{ | ||
if (empty($tokens) || $tokens[0][0] !== T_OPEN_TAG) { | ||
return false; | ||
} | ||
|
||
try { | ||
$tokens = SyntaxNormalizer::normalizeSyntax($tokens, true); | ||
} catch (Exception $e) { | ||
self::requestIssue($absFilePath); | ||
|
||
return false; | ||
} | ||
|
||
if (SyntaxNormalizer::$hasChange && self::getConfirm($absFilePath)) { | ||
Refactor::saveTokens($absFilePath, $tokens); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static function getConfirm($filePath) | ||
{ | ||
$filePath = FilePath::getRelativePath($filePath); | ||
|
||
return ErrorPrinter::singleton()->printer->confirm('Replacing endif in: '.$filePath); | ||
} | ||
|
||
private static function requestIssue(string $path) | ||
{ | ||
dump('(O_o) Well, It seems we had some problem parsing the contents of: (o_O)'); | ||
dump('Submit an issue on github: https://github.com/imanghafoori1/microscope'); | ||
dump('Send us the contents of: '.$path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters