Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pint #195

Merged
merged 4 commits into from
Aug 28, 2023
Merged
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
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,26 @@ jobs:

- name: PHPStan tests
run: composer phpstan

## PINT
pint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@2.21.0
with:
php-version: '8.0'
coverage: none
tools: cs2pr
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update: true

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: Run Pint
run: composer exec -- pint --test --format=checkstyle | cs2pr
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"league/uri": "^6.0",
"symfony/browser-kit": "^6.0",
"symfony/http-client": "^6.0",
"symfony/css-selector": "^6.0"
"symfony/css-selector": "^6.0",
"laravel/pint": "^1.5"
},
"require-dev": {
"symfony/thanks": "^1.0.0",
Expand All @@ -47,7 +48,8 @@
},
"scripts": {
"test": "./vendor/phpunit/phpunit/phpunit --cache-result --cache-result-file=.tmp/phpunit --order-by=defects --colors=always --stop-on-failure",
"phpstan": "vendor/bin/phpstan analyse"
"phpstan": "./vendor/bin/phpstan analyse",
"pint": "./vendor/bin/pint --verbose --test"
},
"funding": [
{
Expand Down
1 change: 0 additions & 1 deletion src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/**
* This class organizes mostly. For individual functionality check the related traits please.
*/

class Core
{
/**
Expand Down
8 changes: 4 additions & 4 deletions src/DataTransferObjects/FeedEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
*
* This isn't aimed at keeping all details but the key values.
*/

class FeedEntry
{
// Support for PHP7.4
public string $title;

public string $description;

public string $link;

/**
* @todo with drop of PHP7.4 we should make these public and remove the initialization above.
*
* @todo with drop of PHP7.4 and 8.0 we should make this `readonly`.
*/
public function __construct(
Expand All @@ -31,7 +31,7 @@ public function __construct(
}

/**
* @param array<string, string> $data
* @param array<string, string> $data
**/
public static function fromArray(array $data): self
{
Expand All @@ -42,4 +42,4 @@ public static function fromArray(array $data): self
$data['link']
);
}
}
}
8 changes: 3 additions & 5 deletions src/PHPScraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PHPScraper
protected $core = null;

/**
* @param PHPScraperConfig $config
* @param PHPScraperConfig $config
*/
public function __construct(array $config = [])
{
Expand All @@ -45,7 +45,7 @@ public function __construct(array $config = [])
/**
* Sets the config, generates the required Clients and updates the core with the new clients.
*
* @param PHPScraperConfig $config
* @param PHPScraperConfig $config
*/
public function setConfig(array $config = []): self
{
Expand Down Expand Up @@ -119,7 +119,6 @@ public function setConfig(array $config = []): self
/**
* Catch calls to properties and process them accordingly.
*
* @param string $name
* @return mixed
*/
public function __get(string $name)
Expand All @@ -131,8 +130,7 @@ public function __get(string $name)
/**
* Catches the method calls and tries to satisfy them.
*
* @param string $name
* @param array<mixed> $arguments
* @param array<mixed> $arguments
* @return mixed
*/
public function __call(string $name, array $arguments = [])
Expand Down
15 changes: 2 additions & 13 deletions src/UsesBrowserKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ trait UsesBrowserKit

/**
* Overwrites the client
*
* @param \Symfony\Component\BrowserKit\HttpBrowser $client
*/
public function setClient(HttpBrowser $client): self
{
Expand All @@ -43,8 +41,6 @@ public function setClient(HttpBrowser $client): self

/**
* Overwrites the httpClient
*
* @param \Symfony\Contracts\HttpClient\HttpClientInterface $httpClient
*/
public function setHttpClient(HttpClientInterface $httpClient): self
{
Expand All @@ -69,8 +65,6 @@ public function client(): HttpBrowser

/**
* Navigates to a new page using an URL.
*
* @param string $url
*/
public function go(string $url): self
{
Expand All @@ -84,9 +78,6 @@ public function go(string $url): self
* Allows to set HTML content to process.
*
* This is intended to be used as a work-around, if you already have the DOM.
*
* @param string $url
* @param string $content
*/
public function setContent(string $url, string $content): self
{
Expand All @@ -98,8 +89,6 @@ public function setContent(string $url, string $content): self

/**
* Fetch an asset from a given absolute or relative URL
*
* @param string $url
*/
public function fetchAsset(string $url): string
{
Expand All @@ -115,7 +104,7 @@ public function fetchAsset(string $url): string
/**
* Click a link (either with title or url)
*
* @param string $titleOrUrl
* @param string $titleOrUrl
*/
public function clickLink($titleOrUrl): self
{
Expand All @@ -133,4 +122,4 @@ public function clickLink($titleOrUrl): self

return $this;
}
}
}
35 changes: 8 additions & 27 deletions src/UsesContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use DonatelloZa\RakePlus\RakePlus;
use League\Uri\Uri;
use Symfony\Component\DomCrawler\Link as DomCrawlerLink;
use Symfony\Component\DomCrawler\Image as DomCrawlerImage;
use Symfony\Component\DomCrawler\Link as DomCrawlerLink;

trait UsesContent
{
Expand All @@ -19,7 +19,6 @@ trait UsesContent
*
* @see https://phpscraper.de/contributing
*/

public function title(): ?string
{
return $this->filterFirstText('//title');
Expand Down Expand Up @@ -103,8 +102,6 @@ public function description(): ?string

/**
* Get the meta collected as an array
*
* @return array
*/
public function metaTags(): array
{
Expand Down Expand Up @@ -252,14 +249,14 @@ public function paragraphs(): array

/**
* Get the paragraphs of the page excluding empty paragraphs.
*
* @return array
*/
public function cleanParagraphs(): array
{
return array_values(array_filter(
$this->paragraphs(),
function ($paragraph) { return $paragraph !== ''; }
function ($paragraph) {
return $paragraph !== '';
}
));
}

Expand Down Expand Up @@ -298,8 +295,6 @@ public function outlineWithParagraphs(): array

/**
* Parses the content outline of the web-page
*
* @return array
*/
public function cleanOutlineWithParagraphs(): array
{
Expand Down Expand Up @@ -391,8 +386,7 @@ protected function prepContent(): array
* @see https://phpscraper.de/examples/extract-keywords.html
* @see /~https://github.com/spekulatius/phpscraper-keyword-scraping-example
*
* @param string $locale (default: 'en_US')
* @return array
* @param string $locale (default: 'en_US')
*/
public function contentKeywords($locale = 'en_US'): array
{
Expand All @@ -418,8 +412,7 @@ public function contentKeywords($locale = 'en_US'): array
* @see https://phpscraper.de/examples/extract-keywords.html
* @see /~https://github.com/spekulatius/phpscraper-keyword-scraping-example
*
* @param string $locale (default: 'en_US')
* @return array
* @param string $locale (default: 'en_US')
*/
public function contentKeywordsWithScores($locale = 'en_US'): array
{
Expand All @@ -433,8 +426,6 @@ public function contentKeywordsWithScores($locale = 'en_US'): array
* Get all links on the page as absolute URLs
*
* @see /~https://github.com/spekulatius/link-scraping-test-beautifulsoup-vs-phpscraper
*
* @return array
*/
public function links(): array
{
Expand All @@ -451,8 +442,6 @@ public function links(): array

/**
* Get all internal links (same root or sub-domain) on the page as absolute URLs
*
* @return array
*/
public function internalLinks(): array
{
Expand All @@ -465,15 +454,13 @@ public function internalLinks(): array
function ($link) use (&$currentRootDomain) {
$linkRootDomain = Uri::createFromString($link)->getHost();

return ($currentRootDomain === $linkRootDomain);
return $currentRootDomain === $linkRootDomain;
}
));
}

/**
* Get all external links on the page as absolute URLs
*
* @return array
*/
public function externalLinks(): array
{
Expand All @@ -486,8 +473,6 @@ public function externalLinks(): array

/**
* Get all links on the page with commonly interesting details
*
* @return array
*/
public function linksWithDetails(): array
{
Expand Down Expand Up @@ -539,8 +524,6 @@ public function linksWithDetails(): array

/**
* Get all images on the page with absolute URLs
*
* @return array
*/
public function images(): array
{
Expand All @@ -559,8 +542,6 @@ public function images(): array

/**
* Get all images on the page with commonly interesting details
*
* @return array
*/
public function imagesWithDetails(): array
{
Expand All @@ -583,4 +564,4 @@ public function imagesWithDetails(): array

return $result;
}
}
}
10 changes: 2 additions & 8 deletions src/UsesFeeds.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ trait UsesFeeds
{
/**
* Returns a guessed sitemap URL based on the current host. Usually it's `/sitemap.xml`.
*
* @return string
*/
public function sitemapUrl(): string
{
Expand Down Expand Up @@ -48,11 +46,8 @@ public function sitemap(?string $url = null): array
);
}


/**
* Returns the usual location (URL) for the static search index.
*
* @return string
*/
public function searchIndexUrl(): string
{
Expand Down Expand Up @@ -89,7 +84,6 @@ public function searchIndex(?string $url = null): array
);
}


/**
* Compiles a list of RSS urls based on the <link>-tags on the current page.
*
Expand All @@ -105,7 +99,7 @@ public function rssUrls(): array
/**
* Fetches a given set of RSS feeds and returns one array with raw data.
*
* @param ?string ...$urls
* @param ?string ...$urls
* @return array $rss
*/
public function rssRaw(?string ...$urls): array
Expand All @@ -119,7 +113,7 @@ public function rssRaw(?string ...$urls): array
/**
* Fetches a given set of RSS feeds and returns one array with raw data.
*
* @param ?string ...$urls
* @param ?string ...$urls
* @return array<FeedEntry> $rss
*/
public function rss(?string ...$urls): array
Expand Down
Loading