Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

James_Moore's avatar

Code Review: Made a simple package

I created a simple package https://github.com/James-N-M/chuck-norris-ipsum after watching the first part of marcel pociot' package development course. Just wondering if anyone has any tips for features, cleaner code etc etc. It was a very simple project to just help solidify some of the concepts i learned. Thanks again

0 likes
4 replies
Sinnbeck's avatar

Looks cool and fun. Code seems clean as well. Unsure why you wrap shuffle though

One idea. Load the facts from thanslstions, allowing them to be translated to other languages. Maybe I would pr Danish. Would be fun to use in prototypes :)

1 like
James_Moore's avatar

@sinnbeck tbh I'm not sure haha I was just playing around maybe ill remove shuffle in a future update, and nice ill look into that I appreciate it the idea :)

FrankClark's avatar
Level 2

When your function has no return, you can use the void return type hint

 public function __construct(Client $client = null): void
 {
    $this->client = $client ?: new Client();
 }

Also if your method returns $this you can use return type hint of self e.g.

public function jokes(int $count = 2): self
    {
        $this->ipsum .= $this->jokesIpsum->jokes($count);

        return $this;
    }

This will just aid your IDE along.

Instead of const API_ENDPOINT = 'http://api.icndb.com/jokes'; you could use an environment variable or config. See Laravel's documentation here : https://laravel.com/docs/5.8/packages#configuration this way you can publish your configuration for the package and the endpoint could be modified per installation

1 like

Please or to participate in this conversation.