Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  simplify code comprehension
  update the doc
  no need to inject the walker as it cannot be herited
  replace travis by github ci
  add psalm
  add exception message wherever possible
  simplify the build of a Directives object during the parsing
  CS
  use a deferred sequence to not force loading the whole robots.txt file in memory
  CS
  update deps
  rename __toString to toString
  ignore phpunit result cache
  require php 7.4
  update to phpunit 8
  • Loading branch information
Baptouuuu committed Feb 5, 2020
2 parents afca295 + 0ff9a00 commit 0b843a5
Show file tree
Hide file tree
Showing 33 changed files with 535 additions and 389 deletions.
2 changes: 0 additions & 2 deletions .gitattributes
@@ -1,5 +1,3 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/tests export-ignore
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,64 @@
name: CI

on: [push]

jobs:
phpunit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['7.4']
name: 'PHPUnit - PHP/${{ matrix.php-version }} - OS/${{ matrix.os }}'
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: xdebug
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
psalm:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.4']
name: 'Psalm - PHP/${{ matrix.php-version }}'
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install
- name: Psalm
run: vendor/bin/psalm --shepherd
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
composer.lock
vendor/
.phpunit.result.cache
6 changes: 0 additions & 6 deletions .scrutinizer.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

27 changes: 11 additions & 16 deletions README.md
@@ -1,10 +1,8 @@
# Robots.txt

| `master` | `develop` |
|----------|-----------|
| [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Innmind/Robots.txt/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Innmind/Robots.txt/?branch=master) | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Innmind/Robots.txt/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/Robots.txt/?branch=develop) |
| [![Code Coverage](https://scrutinizer-ci.com/g/Innmind/Robots.txt/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Innmind/Robots.txt/?branch=master) | [![Code Coverage](https://scrutinizer-ci.com/g/Innmind/Robots.txt/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/Robots.txt/?branch=develop) |
| [![Build Status](https://scrutinizer-ci.com/g/Innmind/Robots.txt/badges/build.png?b=master)](https://scrutinizer-ci.com/g/Innmind/Robots.txt/build-status/master) | [![Build Status](https://scrutinizer-ci.com/g/Innmind/Robots.txt/badges/build.png?b=develop)](https://scrutinizer-ci.com/g/Innmind/Robots.txt/build-status/develop) |
[![codecov](https://codecov.io/gh/Innmind/Robots.txt/branch/develop/graph/badge.svg)](https://codecov.io/gh/Innmind/Robots.txt)
[![Build Status](https://github.com/Innmind/Robots.txt/workflows/CI/badge.svg)](https://github.com/Innmind/Robots.txt/actions?query=workflow%3ACI)
[![Type Coverage](https://shepherd.dev/github/Innmind/Robots.txt/coverage.svg)](https://shepherd.dev/github/Innmind/Robots.txt)

Robots.txt parser

Expand All @@ -17,21 +15,18 @@ composer require innmind/robots-txt
## Usage

```php
use Innmind\RobotsTxt\{
Parser,
Parser\Walker,
};
use Innmind\HttpTransport\Transport;
use Innmind\RobotsTxt\Parser;
use Innmind\OperatingSystem\Factory;
use Innmind\Url\Url;

$os = Factory::build();
$parse = new Parser(
/* an instance of Transport */,
new Walker,
'My user agent'
$os->remote()->http(),
'My user agent',
);
$robots = $parse(Url::fromString('https://github.com/robots.txt'));
$robots->disallows('My user agent', Url::fromString('/humans.txt')); //false
$robots->disallows('My user agent', Url::fromString('/any/other/url')); //true
$robots = $parse(Url::of('https://github.com/robots.txt'));
$robots->disallows('My user agent', Url::of('/humans.txt')); //false
$robots->disallows('My user agent', Url::of('/any/other/url')); //true
```

**Note**: Here only the path `/humans.txt` is allowed because by default github disallows any user agent to crawl there website except for this file.
11 changes: 6 additions & 5 deletions composer.json
Expand Up @@ -14,13 +14,14 @@
}
},
"require": {
"php": "~7.2",
"innmind/url": "~2.0",
"innmind/immutable": "~2.12",
"innmind/http-transport": "~4.0"
"php": "~7.4",
"innmind/url": "~3.0",
"innmind/immutable": "~3.3",
"innmind/http-transport": "~5.0"
},
"require-dev": {
"phpunit/phpunit": "~7.0"
"phpunit/phpunit": "~8.0",
"vimeo/psalm": "^3.8"
},
"scripts": {
"test" : "vendor/bin/phpunit --colors=always"
Expand Down
19 changes: 19 additions & 0 deletions psalm.xml
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />
</issueHandlers>
</psalm>
6 changes: 3 additions & 3 deletions src/Allow.php
Expand Up @@ -5,7 +5,7 @@

final class Allow
{
private $pattern;
private UrlPattern $pattern;

public function __construct(UrlPattern $pattern)
{
Expand All @@ -17,8 +17,8 @@ public function matches(string $url): bool
return $this->pattern->matches($url);
}

public function __toString(): string
public function toString(): string
{
return 'Allow: '.$this->pattern;
return 'Allow: '.$this->pattern->toString();
}
}
6 changes: 3 additions & 3 deletions src/CrawlDelay.php
Expand Up @@ -7,12 +7,12 @@

final class CrawlDelay
{
private $value;
private int $value;

public function __construct(int $value)
{
if ($value < 0) {
throw new DomainException;
throw new DomainException((string) $value);
}

$this->value = $value;
Expand All @@ -23,7 +23,7 @@ public function toInt(): int
return $this->value;
}

public function __toString(): string
public function toString(): string
{
return 'Crawl-delay: '.$this->value;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Directives.php
Expand Up @@ -3,17 +3,17 @@

namespace Innmind\RobotsTxt;

use Innmind\Url\UrlInterface;
use Innmind\Url\Url;

interface Directives
{
public function targets(string $userAgent): bool;
public function disallows(UrlInterface $url): bool;
public function disallows(Url $url): bool;

/**
* Delay in seconds
*/
public function crawlDelay(): CrawlDelay;
public function hasCrawlDelay(): bool;
public function __toString(): string;
public function toString(): string;
}

0 comments on commit 0b843a5

Please sign in to comment.