Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
fixes & updated to support laravel 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
abdumu committed Sep 14, 2019
1 parent 707c2ad commit 1e223e2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 25 deletions.
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
}
],
"require": {
"illuminate/console": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0",
"illuminate/view": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0",
"illuminate/filesystem": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0",
"illuminate/support": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0"
"php": "~7.1",
"illuminate/console": "~5.5|^6.0",
"illuminate/view": "~5.5|^6.0",
"illuminate/filesystem": "~5.5|^6.0",
"illuminate/support": "~5.5|^6.0"
},
"require-dev": {
"phpunit/phpunit": "^6.1|^8.0"
"phpunit/phpunit": "~6.5"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 15 additions & 9 deletions src/Analyze.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Container\Container;
use Illuminate\Contracts\View\View;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\Compilers\BladeCompiler;


Expand All @@ -15,14 +13,13 @@ class Analyze
/** @var \Illuminate\View\Compilers\BladeCompiler */
protected $compiler;

/** @var \Illuminate\View\FileViewFinder */
protected $finder;

protected $code;

/** @var \Illuminate\Support\Collection */
protected $directives;

protected $viewsPaths;

protected $viewInfo;
protected $nestedLevels;
protected $directivesInfo;
Expand All @@ -33,7 +30,9 @@ public function __construct()
$app = Container::getInstance();

$this->compiler = $app->make(BladeCompiler::class);
$this->finder = $app->make(Factory::class)->getFinder();
$this->viewsPaths = array_map(function($path) {
return realpath($path) ?: $path;
}, $app->config['view']['paths']);
}

/**
Expand All @@ -46,9 +45,16 @@ public static function view($viewName)

public function analyze($viewName)
{
try {
$viewPath = $this->finder->find($viewName);
} catch (\InvalidArgumentException $e) {
$viewPath = '';
$viewName = str_replace('.', '/', $viewName).'.blade.php';

foreach ((array) $this->viewsPaths as $path) {
if (file_exists($path.'/'.$viewName)) {
$viewPath = $path.'/'.$viewName;
}
}

if(empty($viewPath)) {
return false;
}

Expand Down
35 changes: 24 additions & 11 deletions src/Commands/BladeAudit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use Illuminate\Support\Str;
use Awssat\BladeAudit\Analyze;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Collection;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;

Expand All @@ -17,16 +18,21 @@ class BladeAudit extends Command

protected $description = 'Extensive information of a blade view';

protected $viewsPaths;
/** @var \Illuminate\Filesystem\Filesystem */
protected $filesystem;

protected $allViewsResult;

public function __construct(Filesystem $filesystem)
public function __construct(Container $app)
{
parent::__construct();

$this->filesystem = $filesystem;
$this->viewsPaths = array_map(function($path) {
return realpath($path) ?: $path;
}, $app->config['view']['paths']);

$this->filesystem = $app->make(Filesystem::class);
}

/**
Expand Down Expand Up @@ -118,7 +124,7 @@ protected function outputOneView($result)

(new Table($this->output))
->setHeaders([
[new TableCell('Audit Notes', ['colspan' => 2])],
[new TableCell('Notes', ['colspan' => 2])],
])
->setStyle('compact')
->setRows(
Expand Down Expand Up @@ -202,7 +208,7 @@ protected function outputAllViews()

(new Table($this->output))
->setHeaders([
[new TableCell('Audit Notes: <fg=cyan>('.$view.')</>', ['colspan' => 2])],
[new TableCell('Notes: <fg=cyan>('.$view.')</>', ['colspan' => 2])],
])
->setStyle('compact')
->setRows(
Expand All @@ -221,14 +227,21 @@ protected function outputAllViews()
*/
protected function getAllViews()
{
return Collection::wrap(
$this->filesystem->allFiles(resource_path('views'))
)->map(function ($file) {
return str_replace(
return Collection::wrap($this->viewsPaths)
->map(function($path) {
return $this->filesystem->allFiles($path) ?? [];
})
->flatten()
->map(function ($file) {
if (Str::endsWith($file, '.blade.php')) {
return str_replace(
[DIRECTORY_SEPARATOR, '.blade.php'],
['.', ''],
Str::after($file, resource_path('views') . DIRECTORY_SEPARATOR)
);
});
);
}
return null;
})
->filter();
}
}

0 comments on commit 1e223e2

Please sign in to comment.