diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ddcec24..24b2b64 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,11 +1,15 @@ version: 2 updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 - ignore: - - dependency-name: spatie/pest-plugin-snapshots - versions: - - 1.0.0 + - package-ecosystem: "composer" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 10 + reviewers: + - "Gummibeer" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + reviewers: + - "Gummibeer" diff --git a/.github/workflows/composer-normalize.yml b/.github/workflows/composer-normalize.yml deleted file mode 100644 index fb8b369..0000000 --- a/.github/workflows/composer-normalize.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: normalize composer.json - -on: - push: - paths: - - 'composer.json' - -jobs: - normalize: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - name: Git checkout - uses: actions/checkout@v2 - - - name: Validate Composer configuration - run: composer validate --strict - - - name: Normalize composer.json - run: | - composer global require ergebnis/composer-normalize - composer normalize --indent-style=space --indent-size=4 --no-check-lock --no-update-lock --no-interaction --ansi - - - uses: stefanzweifel/git-auto-commit-action@v4.0.0 - with: - commit_message: normalize composer.json diff --git a/.github/workflows/markdown-normalize.yml b/.github/workflows/markdown-normalize.yml deleted file mode 100644 index 95e9fa4..0000000 --- a/.github/workflows/markdown-normalize.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: normalize markdown - -on: - push: - paths: - - '*.md' - -jobs: - normalize: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - name: Git checkout - uses: actions/checkout@v2 - - - name: Prettify markdown - uses: creyD/prettier_action@v3.0 - with: - prettier_options: --write **/*.md diff --git a/.github/workflows/pest.yml b/.github/workflows/pest.yml new file mode 100644 index 0000000..e164d8e --- /dev/null +++ b/.github/workflows/pest.yml @@ -0,0 +1,23 @@ +name: pest + +on: + push: + pull_request: + +jobs: + test: + name: P${{ matrix.php }} - ${{ matrix.dependency-version }} + runs-on: ubuntu-latest + timeout-minutes: 15 + strategy: + matrix: + php: ['8.1', '8.2'] + dependency-version: [prefer-lowest, prefer-stable] + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, json + - run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest + - run: vendor/bin/pest diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml new file mode 100644 index 0000000..6299115 --- /dev/null +++ b/.github/workflows/pint.yml @@ -0,0 +1,17 @@ +name: pint + +on: + push: + pull_request: + +jobs: + phpcs: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + - run: composer install --no-interaction --no-scripts + - run: vendor/bin/pint --test diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml deleted file mode 100644 index a5927a5..0000000 --- a/.github/workflows/run-tests.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: run-tests - -on: - push: - pull_request: - schedule: - - cron: '0 0 * * *' - -jobs: - test: - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository - - runs-on: ubuntu-latest - - strategy: - matrix: - php: [8.0, 7.4] - dependency-version: [prefer-lowest, prefer-stable] - - name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - - steps: - - uses: actions/checkout@v2 - - - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: mbstring, json - - - uses: actions/cache@v2 - with: - path: ~/.composer/cache/files - key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - restore-keys: | - dependencies-php-${{ matrix.php }}-composer- - dependencies-php- - - - run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - - - run: vendor/bin/pest diff --git a/.github/workflows/stale-issues.yml b/.github/workflows/stale-issues.yml deleted file mode 100644 index bdc7d06..0000000 --- a/.github/workflows/stale-issues.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: "Close stale issues" -on: - schedule: - - cron: "0 0 * * *" - -jobs: - default: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v2.0.0 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days' - stale-issue-label: 'stale' - exempt-issue-labels: 'bug,enhancement,documentation,help wanted,next release,next major release' - days-before-stale: 21 - days-before-close: 7 - - invalid: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v2.0.0 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue is stale because it has been labeled as invalid.' - stale-issue-label: 'stale' - only-labels: 'invalid' - days-before-stale: 1 - days-before-close: 2 - - duplicate: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v2.0.0 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue is stale because it has been labeled as duplicate.' - stale-issue-label: 'stale' - only-labels: 'duplicate' - days-before-stale: 1 - days-before-close: 2 - - wontfix: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v2.0.0 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'This issue is stale because it has been labeled as wontfix.' - stale-issue-label: 'stale' - only-labels: 'wontfix' - days-before-stale: 1 - days-before-close: 2 diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 6deb832..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,3 +0,0 @@ -preset: laravel - -risky: true diff --git a/README.md b/README.md index 4f371a7..0cb8d58 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ [![Offset Earth](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-green?style=for-the-badge)](https://plant.treeware.earth/Astrotomic/php-open-graph) [![Larabelles](https://img.shields.io/badge/Larabelles-%F0%9F%A6%84-lightpink?style=for-the-badge)](https://www.larabelles.com/) -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/php-open-graph/run-tests?style=flat-square&logoColor=white&logo=github&label=Tests)](https://github.com/Astrotomic/php-open-graph/actions?query=workflow%3Arun-tests) -[![StyleCI](https://styleci.io/repos/82821437/shield)](https://styleci.io/repos/82821437) +[![pest](https://img.shields.io/github/workflow/status/Astrotomic/php-open-graph/pest?style=flat-square&logoColor=white&logo=github&label=Tests)](https://github.com/Astrotomic/php-open-graph/actions?query=workflow%3Apest) +[![pint](https://img.shields.io/github/workflow/status/Astrotomic/php-open-graph/pint?style=flat-square&logoColor=white&logo=github&label=CS)](https://github.com/Astrotomic/php-open-graph/actions?query=workflow%3Apint) [![Total Downloads](https://img.shields.io/packagist/dt/astrotomic/php-open-graph.svg?label=Downloads&style=flat-square)](https://packagist.org/packages/astrotomic/php-open-graph) This package provides a fluent PHP OOP builder for [Open Graph protocol](https://ogp.me) and [Twitter Cards](https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/abouts-cards). @@ -44,36 +44,37 @@ echo OpenGraph::website('Example') #### Global -- `\Astrotomic\OpenGraph\Types\Website` - `\Astrotomic\OpenGraph\Types\Article` -- `\Astrotomic\OpenGraph\Types\Profile` - `\Astrotomic\OpenGraph\Types\Book` +- `\Astrotomic\OpenGraph\Types\Profile` +- `\Astrotomic\OpenGraph\Types\Website` #### Music - `\Astrotomic\OpenGraph\Types\Music\Album` - `\Astrotomic\OpenGraph\Types\Music\Playlist` -- `\Astrotomic\OpenGraph\Types\Music\Song` - `\Astrotomic\OpenGraph\Types\Music\RadioStation` +- `\Astrotomic\OpenGraph\Types\Music\Song` #### Video -- `\Astrotomic\OpenGraph\Types\Video\Movie` -- `\Astrotomic\OpenGraph\Types\Video\TvShow` - `\Astrotomic\OpenGraph\Types\Video\Episode` +- `\Astrotomic\OpenGraph\Types\Video\Movie` - `\Astrotomic\OpenGraph\Types\Video\Other` +- `\Astrotomic\OpenGraph\Types\Video\TvShow` #### Twitter -- `\Astrotomic\OpenGraph\Types\Twitter\Summary` -- `\Astrotomic\OpenGraph\Types\Twitter\SummaryLargeImage` +- `\Astrotomic\OpenGraph\Types\Twitter\App` - `\Astrotomic\OpenGraph\Types\Twitter\Player` +- `\Astrotomic\OpenGraph\Types\Twitter\SummaryLargeImage` +- `\Astrotomic\OpenGraph\Types\Twitter\Summary` ### Structured Properties +- `\Astrotomic\OpenGraph\StructuredProperties\Audio` - `\Astrotomic\OpenGraph\StructuredProperties\Image` - `\Astrotomic\OpenGraph\StructuredProperties\Video` -- `\Astrotomic\OpenGraph\StructuredProperties\Audio` ## Testing diff --git a/composer.json b/composer.json index a42a89e..438fbff 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,10 @@ { "name": "astrotomic/php-open-graph", "description": "Easily generate Open Graph tags", + "license": "MIT", "keywords": [ "open-graph" ], - "homepage": "https://github.com/Astrotomic/php-open-graph", - "license": "MIT", "authors": [ { "name": "Tom Witkowski", @@ -14,31 +13,31 @@ "role": "Developer" } ], + "homepage": "https://github.com/Astrotomic/php-open-graph", "require": { - "php": "^7.1 || ^8.0", + "php": "^8.1", "astrotomic/php-conditional-proxy": "^0.2.1" }, "require-dev": { - "pestphp/pest": "^0.3.0", - "spatie/pest-plugin-snapshots": "^0.3.0" - }, - "suggest": { - "php": "^7.4" - }, - "config": { - "sort-packages": true, - "allow-plugins": { - "pestphp/pest-plugin": true - } + "laravel/pint": "^1.0", + "pestphp/pest": "^2.0", + "spatie/pest-plugin-snapshots": "^2.0" }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "Astrotomic\\OpenGraph\\": "src" } }, - "minimum-stability": "dev", - "prefer-stable": true, + "config": { + "allow-plugins": { + "pestphp/pest-plugin": true + }, + "sort-packages": true + }, "scripts": { - "test": "vendor/bin/pest" + "fix": "@php vendor/bin/pint", + "test": "@php vendor/bin/pest" } } diff --git a/src/OpenGraph.php b/src/OpenGraph.php index f89583d..dd2c16c 100644 --- a/src/OpenGraph.php +++ b/src/OpenGraph.php @@ -17,62 +17,62 @@ class OpenGraph { - public static function website(?string $title = null): Website + public static function website(string $title = null): Website { return Website::make($title); } - public static function article(?string $title = null): Article + public static function article(string $title = null): Article { return Article::make($title); } - public static function book(?string $title = null): Book + public static function book(string $title = null): Book { return Book::make($title); } - public static function profile(?string $title = null): Profile + public static function profile(string $title = null): Profile { return Profile::make($title); } - public static function movie(?string $title = null): Movie + public static function movie(string $title = null): Movie { return Movie::make($title); } - public static function tvShow(?string $title = null): TvShow + public static function tvShow(string $title = null): TvShow { return TvShow::make($title); } - public static function episode(?string $title = null): Episode + public static function episode(string $title = null): Episode { return Episode::make($title); } - public static function other(?string $title = null): Other + public static function other(string $title = null): Other { return Other::make($title); } - public static function album(?string $title = null): Album + public static function album(string $title = null): Album { return Album::make($title); } - public static function song(?string $title = null): Song + public static function song(string $title = null): Song { return Song::make($title); } - public static function playlist(?string $title = null): Playlist + public static function playlist(string $title = null): Playlist { return Playlist::make($title); } - public static function radioStation(?string $title = null): RadioStation + public static function radioStation(string $title = null): RadioStation { return RadioStation::make($title); } diff --git a/src/Twitter.php b/src/Twitter.php index 7fe2f62..95cae66 100644 --- a/src/Twitter.php +++ b/src/Twitter.php @@ -8,17 +8,17 @@ class Twitter { - public static function summary(?string $title = null): Summary + public static function summary(string $title = null): Summary { return Summary::make($title); } - public static function summaryLargeImage(?string $title = null): SummaryLargeImage + public static function summaryLargeImage(string $title = null): SummaryLargeImage { return SummaryLargeImage::make($title); } - public static function player(?string $title = null): Player + public static function player(string $title = null): Player { return Player::make($title); } diff --git a/src/TwitterType.php b/src/TwitterType.php index ab81b5a..8b78ae7 100644 --- a/src/TwitterType.php +++ b/src/TwitterType.php @@ -6,13 +6,13 @@ abstract class TwitterType extends BaseObject { protected const PREFIX = 'twitter'; - public function __construct(?string $title = null) + public function __construct(string $title = null) { $this->setProperty(self::PREFIX, 'card', $this->type); $this->when($title)->title($title); } - public static function make(?string $title = null) + public static function make(string $title = null) { return new static($title); } @@ -38,7 +38,7 @@ public function description(string $description) return $this; } - public function image(string $image, ?string $alt = null) + public function image(string $image, string $alt = null) { $this->setProperty(self::PREFIX, 'image', $image); $this->when($alt)->setProperty(self::PREFIX, 'image:alt', $alt); diff --git a/src/Type.php b/src/Type.php index 2fa459b..4fae5a8 100644 --- a/src/Type.php +++ b/src/Type.php @@ -11,13 +11,13 @@ abstract class Type extends BaseObject /** @var string */ protected $type; - public function __construct(?string $title = null) + public function __construct(string $title = null) { $this->setProperty('og', 'type', $this->type); $this->when($title)->title($title); } - public static function make(?string $title = null) + public static function make(string $title = null) { return new static($title); } @@ -72,8 +72,7 @@ public function alternateLocale(string $locale) } /** - * @param Image|string $image - * + * @param Image|string $image * @return $this */ public function image($image) @@ -90,7 +89,7 @@ public function image($image) } /** - * @param Video|string $video + * @param Video|string $video * @return $this */ public function video($video) @@ -107,7 +106,7 @@ public function video($video) } /** - * @param Audio|string $audio + * @param Audio|string $audio * @return $this */ public function audio($audio) diff --git a/src/Types/Music/Album.php b/src/Types/Music/Album.php index b3dc8d0..2a5db74 100644 --- a/src/Types/Music/Album.php +++ b/src/Types/Music/Album.php @@ -19,7 +19,7 @@ public function musician(string $url) return $this; } - public function song(string $url, ?int $disc = null, ?int $track = null) + public function song(string $url, int $disc = null, int $track = null) { $this->addProperty(self::PREFIX, 'song', $url); $this->when($disc > 0)->addProperty(self::PREFIX, 'song:disc', $disc); diff --git a/src/Types/Music/Playlist.php b/src/Types/Music/Playlist.php index c04f437..14e75dc 100644 --- a/src/Types/Music/Playlist.php +++ b/src/Types/Music/Playlist.php @@ -18,7 +18,7 @@ public function creator(string $url) return $this; } - public function song(string $url, ?int $disc = null, ?int $track = null) + public function song(string $url, int $disc = null, int $track = null) { $this->addProperty(self::PREFIX, 'song', $url); $this->when($disc > 0)->addProperty(self::PREFIX, 'song:disc', $disc); diff --git a/src/Types/Music/Song.php b/src/Types/Music/Song.php index ff6658e..01ddbed 100644 --- a/src/Types/Music/Song.php +++ b/src/Types/Music/Song.php @@ -25,7 +25,7 @@ public function musician(string $url) return $this; } - public function album(string $url, ?int $disc = null, ?int $track = null) + public function album(string $url, int $disc = null, int $track = null) { $this->addProperty(self::PREFIX, 'album', $url); $this->when($disc > 0)->addProperty(self::PREFIX, 'album:disc', $disc); diff --git a/src/Types/Twitter/App.php b/src/Types/Twitter/App.php index 8fbe32f..2e8f9bf 100644 --- a/src/Types/Twitter/App.php +++ b/src/Types/Twitter/App.php @@ -9,7 +9,7 @@ class App extends TwitterType /** @var string */ protected $type = 'app'; - public function iPhoneApp(string $name, string $iPhoneAppId, ?string $iPhoneAppUrl = null) + public function iPhoneApp(string $name, string $iPhoneAppId, string $iPhoneAppUrl = null) { $this->setProperty(self::PREFIX, 'app:name:iphone', $name); $this->setProperty(self::PREFIX, 'app:id:iphone', $iPhoneAppId); @@ -20,7 +20,7 @@ public function iPhoneApp(string $name, string $iPhoneAppId, ?string $iPhoneAppU return $this; } - public function iPadApp(string $name, string $iPadAppId, ?string $iPadAppUrl = null) + public function iPadApp(string $name, string $iPadAppId, string $iPadAppUrl = null) { $this->setProperty(self::PREFIX, 'app:name:ipad', $name); $this->setProperty(self::PREFIX, 'app:id:ipad', $iPadAppId); @@ -31,7 +31,7 @@ public function iPadApp(string $name, string $iPadAppId, ?string $iPadAppUrl = n return $this; } - public function googlePlayApp(string $name, string $googlePlayAppId, ?string $googlePlayAppUrl = null) + public function googlePlayApp(string $name, string $googlePlayAppId, string $googlePlayAppUrl = null) { $this->setProperty(self::PREFIX, 'app:name:googleplay', $name); $this->setProperty(self::PREFIX, 'app:id:googleplay', $googlePlayAppId); diff --git a/src/Types/Video/Episode.php b/src/Types/Video/Episode.php index af8aedc..ceb2a3d 100644 --- a/src/Types/Video/Episode.php +++ b/src/Types/Video/Episode.php @@ -19,7 +19,7 @@ public function series(string $url) return $this; } - public function actor(string $url, ?string $role = null) + public function actor(string $url, string $role = null) { $this->addProperty(self::PREFIX, 'actor', $url); $this->when($role)->addProperty(self::PREFIX, 'actor:role', $role); diff --git a/src/Types/Video/Movie.php b/src/Types/Video/Movie.php index a791ab1..47d7a4e 100644 --- a/src/Types/Video/Movie.php +++ b/src/Types/Video/Movie.php @@ -12,7 +12,7 @@ class Movie extends Type /** @var string */ protected $type = 'video.movie'; - public function actor(string $url, ?string $role = null) + public function actor(string $url, string $role = null) { $this->addProperty(self::PREFIX, 'actor', $url); $this->when($role)->addProperty(self::PREFIX, 'actor:role', $role); diff --git a/src/Types/Video/Other.php b/src/Types/Video/Other.php index 560078f..7494918 100644 --- a/src/Types/Video/Other.php +++ b/src/Types/Video/Other.php @@ -12,7 +12,7 @@ class Other extends Type /** @var string */ protected $type = 'video.other'; - public function actor(string $url, ?string $role = null) + public function actor(string $url, string $role = null) { $this->addProperty(self::PREFIX, 'actor', $url); $this->when($role)->addProperty(self::PREFIX, 'actor:role', $role); diff --git a/src/Types/Video/TvShow.php b/src/Types/Video/TvShow.php index c94bfe8..fef7a67 100644 --- a/src/Types/Video/TvShow.php +++ b/src/Types/Video/TvShow.php @@ -12,7 +12,7 @@ class TvShow extends Type /** @var string */ protected $type = 'video.tv_show'; - public function actor(string $url, ?string $role = null) + public function actor(string $url, string $role = null) { $this->addProperty(self::PREFIX, 'actor', $url); $this->when($role)->addProperty(self::PREFIX, 'actor:role', $role); diff --git a/tests/GlobalTypesTest.php b/tests/GlobalTypesTest.php index dbcedf9..7cec002 100644 --- a/tests/GlobalTypesTest.php +++ b/tests/GlobalTypesTest.php @@ -6,6 +6,7 @@ use Astrotomic\OpenGraph\Types\Book; use Astrotomic\OpenGraph\Types\Profile; use Astrotomic\OpenGraph\Types\Website; + use function Spatie\Snapshots\{assertMatchesHtmlSnapshot}; it('can generate website tags', function () { @@ -39,7 +40,8 @@ ->locale('en_US') ->alternateLocale('en_GB') ->siteName('Example') - ->image(new class() { + ->image(new class() + { public function __toString() { return 'http://www.example.com/image1.jpg'; diff --git a/tests/MusicTypesTest.php b/tests/MusicTypesTest.php index 4119631..ac1db5c 100644 --- a/tests/MusicTypesTest.php +++ b/tests/MusicTypesTest.php @@ -4,6 +4,7 @@ use Astrotomic\OpenGraph\Types\Music\Playlist; use Astrotomic\OpenGraph\Types\Music\RadioStation; use Astrotomic\OpenGraph\Types\Music\Song; + use function Spatie\Snapshots\{assertMatchesHtmlSnapshot}; it('can generate song tags', function () { diff --git a/tests/VideoTypesTest.php b/tests/VideoTypesTest.php index abdda3e..aaea598 100644 --- a/tests/VideoTypesTest.php +++ b/tests/VideoTypesTest.php @@ -6,6 +6,7 @@ use Astrotomic\OpenGraph\Types\Video\Movie; use Astrotomic\OpenGraph\Types\Video\Other; use Astrotomic\OpenGraph\Types\Video\TvShow; + use function Spatie\Snapshots\{assertMatchesHtmlSnapshot}; it('can generate movie tags', function () {