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
24 changes: 20 additions & 4 deletions src/Scanners/BasePackageScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,30 @@ abstract class BasePackageScanner
public function __construct(protected string $path) {}

/**
* @return \Illuminate\Support\Collection<int, \Laravel\Roster\Package|\Laravel\Roster\Approach>
* Check if the scanner can handle the given path
*/
abstract public function scan(): Collection;
public function canScan(): bool
{
return file_exists($this->lockFilePath());
}

/**
* Check if the scanner can handle the given path
* Returns the expected lock file name
*/
abstract public function lockFile(): string;

/**
* Get the file path of the lock file
*/
protected function lockFilePath(): string
{
return $this->path.$this->lockFile();
}

/**
* @return \Illuminate\Support\Collection<int, \Laravel\Roster\Package|\Laravel\Roster\Approach>
*/
abstract public function canScan(): bool;
abstract public function scan(): Collection;

/**
* Process dependencies and add them to the mapped items collection
Expand Down
15 changes: 6 additions & 9 deletions src/Scanners/BunPackageLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@

class BunPackageLock extends BasePackageScanner
{
public function lockFile(): string
{
return 'bun.lock';
}

/**
* @return \Illuminate\Support\Collection<int, \Laravel\Roster\Package|\Laravel\Roster\Approach>
*/
public function scan(): Collection
{
$mappedItems = collect();
$lockFilePath = $this->path.'bun.lock';
$lockFilePath = $this->lockFilePath();

$contents = $this->validateFile($lockFilePath);
if ($contents === null) {
Expand Down Expand Up @@ -50,12 +55,4 @@ public function scan(): Collection

return $mappedItems;
}

/**
* Check if the scanner can handle the given path
*/
public function canScan(): bool
{
return file_exists($this->path.'bun.lock');
}
}
15 changes: 6 additions & 9 deletions src/Scanners/NpmPackageLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@

class NpmPackageLock extends BasePackageScanner
{
public function lockFile(): string
{
return 'package-lock.json';
}

/**
* @return \Illuminate\Support\Collection<int, \Laravel\Roster\Package|\Laravel\Roster\Approach>
*/
public function scan(): Collection
{
$mappedItems = collect();
$lockFilePath = $this->path.'package-lock.json';
$lockFilePath = $this->lockFilePath();

$contents = $this->validateFile($lockFilePath);
if ($contents === null) {
Expand Down Expand Up @@ -51,12 +56,4 @@ public function scan(): Collection

return $mappedItems;
}

/**
* Check if the scanner can handle the given path
*/
public function canScan(): bool
{
return file_exists($this->path.'package-lock.json');
}
}
15 changes: 6 additions & 9 deletions src/Scanners/PnpmPackageLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@

class PnpmPackageLock extends BasePackageScanner
{
public function lockFile(): string
{
return 'pnpm-lock.yaml';
}

/**
* @return \Illuminate\Support\Collection<int, \Laravel\Roster\Package|\Laravel\Roster\Approach>
*/
public function scan(): Collection
{
$mappedItems = collect();
$lockFilePath = $this->path.'pnpm-lock.yaml';
$lockFilePath = $this->lockFilePath();

$contents = $this->validateFile($lockFilePath, 'PNPM lock');
if ($contents === null) {
Expand Down Expand Up @@ -62,12 +67,4 @@ public function scan(): Collection

return $mappedItems;
}

/**
* Check if the scanner can handle the given path
*/
public function canScan(): bool
{
return file_exists($this->path.'pnpm-lock.yaml');
}
}
15 changes: 6 additions & 9 deletions src/Scanners/YarnPackageLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@

class YarnPackageLock extends BasePackageScanner
{
public function lockFile(): string
{
return 'yarn.lock';
}

/**
* @return \Illuminate\Support\Collection<int, \Laravel\Roster\Package|\Laravel\Roster\Approach>
*/
public function scan(): Collection
{
$mappedItems = collect([]);
$lockFilePath = $this->path.'yarn.lock';
$lockFilePath = $this->lockFilePath();

$contents = $this->validateFile($lockFilePath, 'Yarn lock');
if ($contents === null) {
Expand Down Expand Up @@ -48,12 +53,4 @@ public function scan(): Collection

return $mappedItems;
}

/**
* Check if the scanner can handle the given path
*/
public function canScan(): bool
{
return file_exists($this->path.'yarn.lock');
}
}