Skip to content
Open
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
15 changes: 15 additions & 0 deletions phpstan-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ public function version(): string
{
return 'fake-laravel-version';
}

public function environmentPath(): string
{
return __DIR__ . '/../';
}

public function environmentFile(): string
{
return '.env';
}
}

if (!class_exists(\Illuminate\Foundation\Application::class)) {
Expand Down Expand Up @@ -45,6 +55,11 @@ public function uri(): string { return ''; }
public function middleware(): array { return []; }
}

if (!interface_exists(\Illuminate\Routing\RouteCollectionInterface::class)) {
interface WardenPHPStanFakeRouteCollectionInterface extends \IteratorAggregate {}
class_alias(WardenPHPStanFakeRouteCollectionInterface::class, \Illuminate\Routing\RouteCollectionInterface::class);
}

class WardenPHPStanFakeRouteFacade
{
/** @return array<int, WardenPHPStanFakeRouteDefinition> */
Expand Down
4 changes: 3 additions & 1 deletion src/Services/Audits/DebugModeAuditService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Dgtlss\Warden\Services\Audits;

use Illuminate\Support\Facades\Route;

class DebugModeAuditService extends AbstractAuditService
{
private array $devPackages = [
Expand Down Expand Up @@ -107,7 +109,7 @@ private function getInstalledPackages(): array

private function hasExposedTestingRoutes(): bool
{
$routeCollection = \Route::getRoutes();
$routeCollection = Route::getRoutes();

// Check debugbar routes separately as they're allowed when APP_DEBUG is true
foreach ($routeCollection as $route) {
Expand Down
5 changes: 3 additions & 2 deletions src/Services/Audits/EnvAuditService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public function getName(): string

public function run(): bool
{
// Check if .env exists
if (!file_exists(base_path('.env'))) {
// Check if .env exists (respect custom environment path)
$envPath = app()->environmentPath() . DIRECTORY_SEPARATOR . app()->environmentFile();
if (!file_exists($envPath)) {
$this->addFinding([
'package' => 'environment',
'title' => 'Missing .env file',
Expand Down
22 changes: 9 additions & 13 deletions src/Services/Audits/StorageAuditService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@

class StorageAuditService extends AbstractAuditService
{
/**
* @var array<string>
*/
private array $directories = [
'storage/framework',
'storage/logs',
'bootstrap/cache',
];

public function getName(): string
{
return 'storage';
}

public function run(): bool
{
foreach ($this->directories as $directory) {
$path = base_path($directory);
$directories = [
storage_path('framework'),
storage_path('logs'),
base_path('bootstrap/cache'),
];

foreach ($directories as $path) {

if (!file_exists($path)) {
$this->addFinding([
'package' => 'storage',
'title' => 'Missing directory: ' . $directory,
'title' => 'Missing directory: ' . $path,
'severity' => 'high',
'cve' => null,
'affected_versions' => null
Expand All @@ -37,7 +33,7 @@ public function run(): bool
if (!is_writable($path)) {
$this->addFinding([
'package' => 'storage',
'title' => 'Directory not writable: ' . $directory,
'title' => 'Directory not writable: ' . $path,
'severity' => 'high',
'cve' => null,
'affected_versions' => null
Expand Down