From de5906f0bbbcea66756d6b65881d7679c3697a74 Mon Sep 17 00:00:00 2001 From: Martin Folkers Date: Sun, 11 Jul 2021 18:04:15 +0200 Subject: [PATCH] v1.1.0 * Add new 'Packages' class * Add methods regarding licenses * Remove code about repo being forked * Update README & test suite --- README.md | 53 ++++++++------ composer.json | 2 +- lib/Driver.php | 98 +++++++------------------- lib/Drivers/Composer.php | 45 ++++++------ lib/Drivers/Node.php | 89 ++++++++++-------------- lib/Drivers/Yarn.php | 8 +-- lib/Packaging/Collection.php | 125 +++++++++++++++++++++++++++++++++ lib/Packaging/Packages.php | 98 ++++++++++++++++++++++++++ lib/Thx.php | 131 ++++++++++++++++++++++++++++++++--- lib/Traits/Caching.php | 4 +- lib/Traits/Remote.php | 78 --------------------- test.php | 19 +++-- 12 files changed, 478 insertions(+), 272 deletions(-) create mode 100644 lib/Packaging/Collection.php create mode 100644 lib/Packaging/Packages.php delete mode 100644 lib/Traits/Remote.php diff --git a/README.md b/README.md index 7a878f3..fc86a04 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,10 @@ $cacheSettings = ['storage' => '/path/to/cache']; # Optional: Cache settings, s **Note:** For available cache drivers & settings, see [here](https://github.com/terrylinooo/simple-cache)! -Passing these options to `Thx::giveBack()` creates an instance: +Passing these options to `new Thx()` creates an instance: ```php -$obj = Thx::giveBack($pkgFile, $lockFile, $cacheDriver, $cacheSettings); +$obj = new Thx($pkgFile, $lockFile, $cacheDriver, $cacheSettings); ``` .. which you may configure to your liking by using: @@ -56,36 +56,40 @@ $obj->setCacheDuration(7); # Cache results for one week $obj->setBlockList(['php', 'some/library']); # Block from being processed ``` -After setting everything up, `spreadLove()` makes some API calls: +After setting everything up, `giveBack()` makes some API calls & returns processed data, wrapped by a `Packages` object: - Composer packages @ https://repo.packagist.org - Node packages @ https://api.npms.io ```php -$obj->spreadLove(); +$processed = $obj->giveBack(); ``` -Currently there are three methods you can use: +At this point, there are three basic methods you can use: - `data()` returns raw data from lockfile for all used packages - `pkgs()` returns processed data for all used packages - `packages()` returns the names of all used packages ```php -# Alternative 1: +# Dump raw data +$raw = $obj->data(); + # Process data -$obj->spreadLove(); +$processed = $obj->giveBack(); # Work with it -$raw = $obj->data(); -$processed = $obj->pkgs(); +$pkgData = $processed->pkgs(); +``` + +For convenience, there are methods to -# Alternative 2: -# Since `spreadLove` allows chaining, you could also do it like this: -$obj->spreadLove()->data(); +- list licenses & number of occurences: `licenses()` +- group packages by license: `byLicense()` -# The second call provides cached data, no performance penalty there -$obj->spreadLove()->pkgs(); +```php +$licenseData = $processed->licenses(); +$groupedByLicense = $processed->byLicense(); ``` @@ -104,13 +108,19 @@ $pkgFile = 'path/to/composer.json'; # or 'package.json' for NPM / Yarn $lockFile = 'path/to/composer.lock' # or 'package-lock.json' for NPM / 'yarn.lock' for Yarn try { - $obj = Thx::giveBack($pkgFile, $lockFile)->spreadLove(); - - # Dump package names - var_dump($obj->packages()) + $obj = new Thx($pkgFile, $lockFile); # Dump (raw) data extracted from lockfiles - var_dump($obj->data()) + var_dump($obj->data()); + + # Process data + $processed = $obj->giveBack(); + + # Dump package data + var_dump($processed->pkgs()) + + # Dump package names + var_dump($processed->packages()) } catch (Exception $e) { # No dependencies found, file not found, .. @@ -125,7 +135,10 @@ try { - [x] Parse yarn v1 lockfiles - [x] Gather information using public APIs - [x] Custom `Exception`s -- [ ] Provide more methods +- [x] Move data manipulation to uniform `Packages` class +- [ ] Provide more (sorting/filtering) methods, eg .. + - [x] .. `byLicense()` = 'MIT' => [...], 'GPL v3' => [...] etc + - .. `byDownloads()` = '2k' => [...], '1k' => [...] etc ## Credits diff --git a/composer.json b/composer.json index ba17306..6e46eee 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Acknowledge the people behind your frontend dependencies - and give thanks!", "type": "library", "license": "MIT", - "version": "1.0.0", + "version": "1.1.0", "keywords": ["gratitude", "appreciation", "gratefulness", "thankfulness"], "homepage": "https://github.com/S1SYPHOS", "scripts": { diff --git a/lib/Driver.php b/lib/Driver.php index 7feaf74..a5b6bd9 100644 --- a/lib/Driver.php +++ b/lib/Driver.php @@ -3,9 +3,7 @@ namespace S1SYPHOS; -use S1SYPHOS\Traits\Caching; use S1SYPHOS\Traits\Helpers; -use S1SYPHOS\Traits\Remote; abstract class Driver @@ -14,9 +12,7 @@ abstract class Driver * Traits */ - use Caching; use Helpers; - use Remote; /** @@ -31,14 +27,6 @@ abstract class Driver public $data = null; - /** - * Processed data - * - * @var array - */ - public $pkgs = null; - - /** * Operating mode identifier * @@ -47,14 +35,6 @@ abstract class Driver public $mode; - /** - * List of packages not to be processed - * - * @var array - */ - public $blockList = []; - - /** * Constructor * @@ -64,32 +44,13 @@ abstract class Driver * @param array $cacheSettings Cache settings * @return void */ - public function __construct(array $pkgData, string $lockFile, string $cacheDriver, array $cacheSettings) + public function __construct(array $pkgData, string $lockFile) { - # Create cache instance - $this->createCache($cacheDriver, $cacheSettings); - # Extract raw data $this->data = $this->extract($pkgData, $lockFile); } - /** - * Setters & getters - */ - - public function setBlockList(int $blockList): void - { - $this->blockList = $blockList; - } - - - public function getBlockList(): array - { - return $this->blockList; - } - - /** * Shared methods */ @@ -97,47 +58,34 @@ public function getBlockList(): array /** * Spreads love * - * @return \S1SYPHOS\Driver + * @param \Shieldon\SimpleCache\Cache $cache Cache object + * @param array $config Configuration options + * @return \S1SYPHOS\Packaging\Packages Processed data */ - public function spreadLove(): \S1SYPHOS\Driver + public function spreadLove(\Shieldon\SimpleCache\Cache $cache, array $config): \S1SYPHOS\Packaging\Packages { # Process raw data - $this->pkgs = $this->process(); - - # Enable chaining - return $this; + return $this->process($cache, $config); } - /** - * Exports raw package data - * - * @return array Raw package data - */ - public function data(): array + protected function fetchRemote(string $apiURL, int $timeout = 3, string $userAgent = ''): string { - return $this->data; - } + # Initialize HTTP client + $client = new \GuzzleHttp\Client(['timeout' => $timeout]); + try { + $response = $client->get($apiURL, ['headers' => ['User-Agent' => $userAgent]]); + } catch (\GuzzleHttp\Exception\TransferException $e) { + return ''; + } - /** - * Exports processed package data - * - * @return array Processed package data - */ - public function pkgs(): array - { - return $this->pkgs; - } + if ($response->getStatusCode() === 200) { + return $response->getBody(); + } - - /** - * Exports package names - * - * @return array Package names - */ - public function packages(): array { - return $this->pluck($this->pkgs, 'name'); + # (3) .. otherwise, transmission *may* have worked + return ''; } @@ -150,7 +98,7 @@ public function packages(): array { * * @param string $dataFile Path to data file * @param string $lockFile Lockfile contents - * @return array + * @return array Extracted data */ abstract protected function extract(array $pkgData, string $lockFile): array; @@ -158,7 +106,9 @@ abstract protected function extract(array $pkgData, string $lockFile): array; /** * Processes raw data * - * @return array Processed data + * @param \Shieldon\SimpleCache\Cache $cache Cache object + * @param array $config Configuration options + * @return \S1SYPHOS\Packaging\Packages Processed data */ - abstract protected function process(): array; + abstract protected function process(\Shieldon\SimpleCache\Cache $cache, array $config): \S1SYPHOS\Packaging\Packages; } diff --git a/lib/Drivers/Composer.php b/lib/Drivers/Composer.php index d64a828..7702008 100644 --- a/lib/Drivers/Composer.php +++ b/lib/Drivers/Composer.php @@ -2,8 +2,8 @@ namespace S1SYPHOS\Drivers; - use S1SYPHOS\Driver; +use S1SYPHOS\Packaging\Packages; class Composer extends Driver @@ -20,16 +20,6 @@ class Composer extends Driver public $mode = 'php'; - /** - * List of packages not to be processed - * - * @var array - */ - public $blockList = [ - 'php', - ]; - - /** * Methods */ @@ -45,50 +35,55 @@ protected function extract(array $pkgData, string $lockFile): array { $lockData = json_decode($lockFile, true); - $phpData = []; + $data = []; foreach ($lockData['packages'] as $pkg) { if (in_array($pkg['name'], array_keys($pkgData['require'])) === true) { - $phpData[$pkg['name']] = $pkg; + $data[$pkg['name']] = $pkg; } } - return $phpData; + return $data; } /** * Processes raw data * - * @return array Processed data + * @param \Shieldon\SimpleCache\Cache $cache Cache object + * @param array $config Configuration options + * @return \S1SYPHOS\Packaging\Packages Processed data */ - protected function process(): array + protected function process(\Shieldon\SimpleCache\Cache $cache, array $config): \S1SYPHOS\Packaging\Packages { - return array_map(function($pkgName, $pkg) { + $pkgs = array_map(function($pkgName, $pkg) use ($cache, $config) { $data = []; # Build unique caching key $hash = md5($pkgName); + # Determine whether data was stored in cache + $fromCache = false; + # Fetch information about package .. - if ($this->cache->has($hash)) { + if ($cache->has($hash)) { # (1) .. from cache (if available) - $data = $this->cache->get($hash); - - $this->fromCache = true; + $data = $cache->get($hash); + $fromCache = true; } if (empty($data)) { # (2) .. from API # Block unwanted libraries - if (in_array($pkgName, $this->blockList) === true) return false; + if (in_array($pkgName, $config['blockList']) === true) return false; # Prepare data for each repository $data['name'] = $pkgName; $data['version'] = str_replace('v', '', strtolower($pkg['version'])); # Fetch additional information from https://packagist.org - $response = $this->fetchRemote('https://repo.packagist.org/p/' . $pkgName . '.json'); + $apiURL = 'https://repo.packagist.org/p/' . $pkgName . '.json'; + $response = $this->fetchRemote($apiURL, $config['timeout'], $config['userAgent']); $response = json_decode($response, true)['packages'][$pkgName]; # Enrich data with results @@ -97,10 +92,12 @@ protected function process(): array $data['url'] = static::rtrim($response[$pkg['version']]['source']['url'], '.git'); # Cache result - $this->cache->set($hash, $data, $this->days2seconds($this->cacheDuration)); + $cache->set($hash, $data, $this->days2seconds($config['cacheDuration'])); } return $data; }, array_keys($this->data), $this->data); + + return new Packages($pkgs); } } diff --git a/lib/Drivers/Node.php b/lib/Drivers/Node.php index 824df96..b8afe07 100644 --- a/lib/Drivers/Node.php +++ b/lib/Drivers/Node.php @@ -4,6 +4,7 @@ use S1SYPHOS\Driver; +use S1SYPHOS\Packaging\Packages; class Node extends Driver @@ -33,7 +34,7 @@ class Node extends Driver */ protected function extract(array $pkgData, string $lockFile): array { - $npmData = []; + $data = []; $lockData = json_decode($lockFile, true); @@ -42,77 +43,61 @@ protected function extract(array $pkgData, string $lockFile): array $pkgName = str_replace('node_modules/', '', $pkgName); if (in_array($pkgName, array_keys($pkgData['dependencies'])) === true) { - $npmData[$pkgName] = $pkg; + $data[$pkgName] = $pkg; } } } - return $npmData; + return $data; } /** * Processes raw data * - * @return array Processed data + * @param \Shieldon\SimpleCache\Cache $cache Cache object + * @param array $config Configuration options + * @return \S1SYPHOS\Packaging\Packages Processed data */ - protected function process(): array + protected function process(\Shieldon\SimpleCache\Cache $cache, array $config): \S1SYPHOS\Packaging\Packages { - return array_map(function($pkgName, $pkg) { - return $this->_process($pkgName, $pkg); - }, array_keys($this->data), $this->data); - } + $pkgs = array_map(function($pkgName, $pkg) use ($cache, $config) { + $data = []; + # Build unique caching key + $hash = md5($pkgName); - /** - * Processes raw data - * - * @return array Processed data - */ - protected function _process(string $pkgName, array $pkg): array - { - $data = []; + # Fetch information about package .. + if ($cache->has($hash)) { + # (1) .. from cache (if available) + $data = $cache->get($hash); + } - # Build unique caching key - $hash = md5($pkgName); + if (empty($data)) { + # (2) .. from API + # Block unwanted libraries + if (in_array($pkgName, $config['blockList']) === true) return false; - # Fetch information about package .. - if ($this->cache->has($hash)) { - # (1) .. from cache (if available) - $data = $this->cache->get($hash); + # Prepare data for each repository + $data['name'] = $pkgName; + $data['version'] = $pkg['version']; - $this->fromCache = true; - } + # Fetch additional information from https://api.npms.io + $apiURL = 'https://api.npms.io/v2/package/' . rawurlencode($pkgName); + $response = $this->fetchRemote($apiURL, $config['timeout'], $config['userAgent']); + $response = json_decode($response)->collected->metadata; - if (empty($data)) { - # (2) .. from API - # Block unwanted libraries - if (in_array($pkgName, $this->blockList) === true) return false; - - # Prepare data for each repository - $data['name'] = $pkgName; - $data['version'] = $pkg['version']; - - # Fetch additional information from https://api.npms.io - $response = $this->fetchRemote('https://api.npms.io/v2/package/' . rawurlencode($pkgName)); - $response = json_decode($response)->collected->metadata; - - $data['license'] = $response->license ?? ''; - $data['description'] = $response->description; - $data['url'] = $response->links->repository; - $data['forked'] = false; - - # Check if it's a forked repository - if (preg_match('/(([0-9])+(\.{0,1}([0-9]))*)/', $data['version']) == false) { - # TODO: Check if that's even a thing - # $data['version'] = $data->version; - $data['forked'] = true; + $data['license'] = $response->license ?? ''; + $data['description'] = $response->description; + $data['url'] = $response->links->repository; + + # Cache result + $cache->set($hash, $data, $this->days2seconds($config['cacheDuration'])); } - # Cache result - $this->cache->set($hash, $data, $this->days2seconds($this->cacheDuration)); - } + return $data; + }, array_keys($this->data), $this->data); - return $data; + return new Packages($pkgs); } } diff --git a/lib/Drivers/Yarn.php b/lib/Drivers/Yarn.php index 9dd09f9..115b5d0 100644 --- a/lib/Drivers/Yarn.php +++ b/lib/Drivers/Yarn.php @@ -21,7 +21,7 @@ class Yarn extends Node */ protected function extract(array $pkgData, string $lockFile): array { - $npmData = []; + $data = []; # Distinguish versions $v1 = '# yarn lockfile v1'; @@ -36,7 +36,7 @@ protected function extract(array $pkgData, string $lockFile): array $pkgName = substr($pkgName, 0, strpos($pkgName, '@')); if (in_array($pkgName, array_keys($pkgData['dependencies'])) === true) { - $npmData[$pkgName] = $pkg; + $data[$pkgName] = $pkg; } } @@ -51,13 +51,13 @@ protected function extract(array $pkgData, string $lockFile): array $pkgName = $this->split($pkgName, '@npm')[0]; if (in_array($pkgName, array_keys($pkgData['dependencies'])) === true) { - $npmData[$pkgName] = $pkg; + $data[$pkgName] = $pkg; } } } } - return $npmData; + return $data; } diff --git a/lib/Packaging/Collection.php b/lib/Packaging/Collection.php new file mode 100644 index 0000000..1cb31ae --- /dev/null +++ b/lib/Packaging/Collection.php @@ -0,0 +1,125 @@ +data); + } + + + /** + * 2) Iterable + */ + + /** + * Returns the current object + * + * @return \S1SYPHOS\Package + */ + public function current() + { + return current($this->data); + } + + + /** + * Returns the current key + * + * @return string + */ + public function key() + { + return key($this->data); + } + + + /** + * Moves the cursor to the next object and returns it + * + * @return \S1SYPHOS\Package + */ + public function next() + { + return next($this->data); + } + + + /** + * Moves the cursor to the previous object and returns it + * + * @return \S1SYPHOS\Package + */ + public function prev() + { + return prev($this->data); + } + + + /** + * Moves the cusor to the first object + * + * @return void + */ + public function rewind(): void + { + reset($this->data); + } + + + /** + * Checks if the current object is valid + * + * @return bool + */ + public function valid(): bool + { + return $this->current() !== false; + } + + + /** + * Exports raw package data + * + * @return array Raw package data + */ + public function data(): array + { + return $this->data; + } +} diff --git a/lib/Packaging/Packages.php b/lib/Packaging/Packages.php new file mode 100644 index 0000000..125af1b --- /dev/null +++ b/lib/Packaging/Packages.php @@ -0,0 +1,98 @@ +data = $data; + } + + + /** + * Methods + */ + + /** + * Exports processed package data + * + * @return array Processed package data + */ + public function pkgs(): array + { + return $this->data; + } + + + /** + * Exports package names + * + * @return array Package names + */ + public function packages(): array { + return $this->pluck($this->data, 'name'); + } + + + /** + * Exports licenses + * + * @return array License names + */ + public function licenses(): array { + $data = []; + + foreach ($this->data as $pkg) { + $license = !empty($pkg['license']) ? $pkg['license'] : 'unknown'; + + if (!isset($data[$license])) { + $data[$license] = 0; + } + + $data[$license]++; + } + + return $data; + } + + + /** + * Exports package data sorted by license + * + * @return array Package names + */ + public function byLicense(): array { + $data = []; + + foreach ($this->data as $pkg) { + $license = !empty($pkg['license']) ? $pkg['license'] : 'unknown'; + + if (!isset($data[$license])) { + $data[$license] = []; + } + + $data[$license][] = $pkg; + } + + return $data; + } +} diff --git a/lib/Thx.php b/lib/Thx.php index 3fc509b..4b7bdc2 100644 --- a/lib/Thx.php +++ b/lib/Thx.php @@ -12,7 +12,8 @@ use S1SYPHOS\Exceptions\NoJuiceException; use S1SYPHOS\Exceptions\NoMannersException; -use \S1SYPHOS\Traits\Helpers; +use S1SYPHOS\Traits\Helpers; +use S1SYPHOS\Traits\Caching; /** @@ -27,33 +28,105 @@ class Thx /** * Current version */ - const VERSION = '1.0.0'; + const VERSION = '1.1.0'; /** * Traits */ + use Caching; use Helpers; /** - * Methods + * List of packages not to be processed + * + * @var array */ + public $blockList = []; + /** - * Gives back & shows some love + * Current package driver + * + * @var \S1SYPHOS\Driver + */ + public $driver; + + + /** + * Defines timeout for API requests (in seconds) + * + * @var int + */ + protected $timeout = 3; + + + /** + * Controls `User-Agent` header + * + * @var string + */ + protected $userAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0'; + + + /** + * Setters & getters + */ + + public function setBlockList(int $blockList): void + { + $this->blockList = $blockList; + } + + + public function getBlockList(): array + { + return $this->blockList; + } + + + public function setTimeout(int $timeout): void + { + $this->timeout = $timeout; + } + + + public function getTimeout(): string + { + return $this->timeout; + } + + + public function setUserAgent(string $userAgent): void + { + $this->userAgent = $userAgent; + } + + + public function getUserAgent(): string + { + return $this->userAgent; + } + + + /** + * Constructor * * @param string $dataFile Path to datafile, eg 'composer.json' or 'package.json' * @param string $lockFile Path tp lockfile, eg 'composer.lock', 'package-lock.json' or 'yarn.lock' * @param string $cacheDriver Cache driver * @param array $cacheSettings Cache settings - - * @return \S1SYPHOS\Driver + * @return void */ - public static function giveBack(string $dataFile, string $lockFile, string $cacheDriver = 'file', array $cacheSettings = []) + public function __construct(string $dataFile, string $lockFile, string $cacheDriver = 'file', array $cacheSettings = []) { - # Validate lockfile + # Create cache instance + $this->cache = $this->createCache($cacheDriver, $cacheSettings); + + # Select appropriate driver for files + # (1) Validate lockfile $lockFilename = basename($lockFile); if ( @@ -64,12 +137,13 @@ public static function giveBack(string $dataFile, string $lockFile, string $cach throw new NoMannersException(sprintf('Unknown lockfile: "%s".', $lockFilename)); } - # Determine package manager + # (2) Determine package manager by .. $lockFile = @file_get_contents($lockFile); - # Load package data + # .. loading package data $pkgData = json_decode(file_get_contents($dataFile), true); + # .. matching filenames $dataFilename = basename($dataFile); if ($dataFilename === 'composer.json') { @@ -96,10 +170,45 @@ public static function giveBack(string $dataFile, string $lockFile, string $cach } } + # (3) Validate datafile if (!isset($class)) { throw new NoMannersException(sprintf('Unknown datafile: "%s".', $dataFilename)); } - return new $class($pkgData, $lockFile, $cacheDriver, $cacheSettings); + # (4) Instantiate appropriate class + $this->driver = new $class($pkgData, $lockFile); + } + + + /** + * Methods + */ + + /** + * Exports raw data + * + * @return array + */ + public function data(): array + { + return $this->driver->data; + } + + + /** + * Gives back & shares the love + * + * @return \S1SYPHOS\Packaging\Packages Processed data + */ + public function giveBack() + { + $config = [ + 'bockList' => $this->blockList, + 'cacheDuration' => $this->cacheDuration, + 'timeout' => $this->timeout, + 'userAgent' => $this->userAgent, + ]; + + return $this->driver->spreadLove($this->cache, $config); } } diff --git a/lib/Traits/Caching.php b/lib/Traits/Caching.php index ae64dbc..93d6d37 100644 --- a/lib/Traits/Caching.php +++ b/lib/Traits/Caching.php @@ -101,13 +101,15 @@ protected function createCache(string $cacheDriver = 'file', array $cacheSetting } # (4) Initialize new cache instance - $this->cache = new \Shieldon\SimpleCache\Cache($cacheDriver, $cacheSettings); + $cache = new \Shieldon\SimpleCache\Cache($cacheDriver, $cacheSettings); # (5) Build database if using SQLite for the first time # TODO: Add check for MySQL, see https://github.com/terrylinooo/simple-cache/issues/8 if ($cacheDriver === 'sqlite' && !file_exists(join([$cacheSettings['storage'], 'cache.sqlite3']))) { $cache->rebuild(); } + + return $cache; } diff --git a/lib/Traits/Remote.php b/lib/Traits/Remote.php deleted file mode 100644 index 0775f83..0000000 --- a/lib/Traits/Remote.php +++ /dev/null @@ -1,78 +0,0 @@ -timeout = $timeout; - } - - - public function getTimeout(): string - { - return $this->timeout; - } - - - public function setUserAgent(string $userAgent): void - { - $this->userAgent = $userAgent; - } - - - public function getUserAgent(): string - { - return $this->userAgent; - } - - - /** - * Methods - */ - - protected function fetchRemote(string $apiURL): string - { - # Initialize HTTP client - $client = new \GuzzleHttp\Client(['timeout' => $this->timeout]); - - try { - $response = $client->get($apiURL, ['headers' => ['User-Agent' => $this->userAgent]]); - } catch (\GuzzleHttp\Exception\TransferException $e) { - return ''; - } - - if ($response->getStatusCode() === 200) { - return $response->getBody(); - } - - # (3) .. otherwise, transmission *may* have worked - return ''; - } -} diff --git a/test.php b/test.php index c9c16a3..6ce9732 100644 --- a/test.php +++ b/test.php @@ -5,19 +5,19 @@ if (isset($argv[1])) { if ($argv[1] === 'composer') { - $obj = S1SYPHOS\Thx::giveBack('tests/composer/composer.json', 'tests/composer/composer.lock'); + $obj = new S1SYPHOS\Thx('tests/composer/composer.json', 'tests/composer/composer.lock'); } if ($argv[1] === 'yarn1') { - $obj = S1SYPHOS\Thx::giveBack('tests/yarn-v1/package.json', 'tests/yarn-v1/yarn.lock'); + $obj = new S1SYPHOS\Thx('tests/yarn-v1/package.json', 'tests/yarn-v1/yarn.lock'); } if ($argv[1] === 'yarn2') { - $obj = S1SYPHOS\Thx::giveBack('tests/yarn-v2/package.json', 'tests/yarn-v2/yarn.lock'); + $obj = new S1SYPHOS\Thx('tests/yarn-v2/package.json', 'tests/yarn-v2/yarn.lock'); } if ($argv[1] === 'npm') { - $obj = S1SYPHOS\Thx::giveBack('tests/npm/package.json', 'tests/npm/package-lock.json'); + $obj = new S1SYPHOS\Thx('tests/npm/package.json', 'tests/npm/package-lock.json'); } } @@ -33,15 +33,20 @@ echo sprintf('Loading tests for "%s" ..%s', $argv[1], "\n"); if ($argv[2] === 'data') { - var_dump($obj->spreadLove()->data()); + var_dump($obj->data()); } if ($argv[2] === 'pkgs') { - var_dump($obj->spreadLove()->pkgs()); + var_dump($obj->giveBack()->pkgs()); } if ($argv[2] === 'packages') { - var_dump($obj->spreadLove()->packages()); + var_dump($obj->giveBack()->packages()); + } + + if ($argv[2] === 'license') { + var_dump($obj->giveBack()->byLicense()); + var_dump($obj->giveBack()->licenses()); } } else {