sissokho/laravel-dev-joke

This package offer a simple way to fetch a random dev joke from the DevJoke API

v2.0.0 2023-06-08 14:48 UTC

This package is auto-updated.

Last update: 2024-05-15 19:59:09 UTC


README

Latest version on packagist MIT Licensed Unit Tests Static Analysis

This package offer a simple way to fetch a random dev joke from this DevJoke API.

Prerequisites

This package requires:

  • PHP 8.1 or higher
  • Laravel 9.0 or higher

If you are on the PHP version 8.0 just use an older version of this package.

Installation

You can install the package via composer:

composer require sissokho/laravel-dev-joke

Usage

This package can be used by resolving the Sissokho\LaravelDevJoke\DevJoke class from the container or by injecting it into a method:

use Sissokho\LaravelDevJoke\DevJoke;

public function joke(DevJoke $devJoke)
{
    $joke = $devJoke->random();

    $joke->question; // retrieve the question
    $joke->punchline; // retrieve the punchline
    $joke->toArray(); // ['question' => 'lorem', 'punchline' => 'ipsum']
}

The randomJoke method will return a Sissokho\LaravelDevJoke\DataTransferObjects\Joke object, which includes the question and the punchline of the joke;

You can also use the Facade:

use Sissokho\LaravelDevJoke\Facades\DevJoke;

$joke = DevJoke::random();

Artisan

An artisan command is provided for you to display a random joke:

php artisan devjoke

The joke is displayed like this:

Screenshot from 2022-08-27 15-19-32

Testing

You can run PHPUnit tests, PHPStan/Larastan static analysis and inspect the code for style errors without changing the files (with Laravel Pint):

composer test

However, you can run these tests separately.

  • Static analysis:
composer test:types
  • PHPUnit tests:
composer test:unit
  • Code inspection:
composer test:style

To fix code style issues, run the following command:

composer stylefix

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

Huge thanks to @askudhay for providing this API.

License

The MIT License (MIT). Please see License File for more information.