#4 - users CRUD #24

Merged
Baakoma merged 24 commits from #4-users-crud into main 2022-01-19 10:55:10 +01:00
2 changed files with 54 additions and 21 deletions
Showing only changes of commit 55eb288e23 - Show all commits

View File

@@ -0,0 +1,49 @@
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
<?php
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
declare(strict_types=1);
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
namespace Toby\Helpers;
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
use Illuminate\Support\Arr;
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
use Illuminate\Support\Facades\Storage;
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
use Illuminate\Support\Str;
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
use SVG\SVG;
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
use Toby\Models\User;
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
class UserAvatarGenerator
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
{
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
public function __construct(protected InitialAvatar $generator)
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
{
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
}
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
public function generateFor(User $user): string
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
{
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
$path = "avatars/{$this->generateUuid()}.svg";
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
Storage::put($path, $this->generate($user));
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
return $path;
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
}
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
protected function generate(User $user): SVG
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
{
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
return $this->generator->rounded()
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
->background($this->getRandomColor())
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
->color("#F4F8FD")
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
->smooth()
krzysztofrewak commented 2022-01-18 13:58:31 +01:00 (Migrated from github.com)
Review

Maybe this would be better?

            ->smooth()
            ->fontSize(0.33)
Maybe this would be better? ```suggestion ->smooth() ->fontSize(0.33) ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
->generateSvg($user->name);
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
}
krzysztofrewak commented 2022-01-18 13:59:14 +01:00 (Migrated from github.com)
Review

Have you checked if that works with Polish signs? Is Łukasz Żbik a valid name for this package?

Have you checked if that works with Polish signs? Is `Łukasz Żbik` a valid name for this package?
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
EwelinaLasowy commented 2022-01-18 14:21:33 +01:00 (Migrated from github.com)
Review

It works.
image

It works. ![image](https://user-images.githubusercontent.com/56546832/149945138-577727a8-0b69-4640-af2b-156505fc593c.png)
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
protected function getRandomColor(): string
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
{
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
$colors = config("colors");
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
return Arr::random($colors);
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
}
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
protected function generateUuid(): string
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
{
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
return Str::uuid()->toString();
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
}
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```
}
krzysztofrewak commented 2022-01-18 14:02:44 +01:00 (Migrated from github.com)
Review
    protected function getRandomColor(string $name): string
    {
        $colors = config("colors");

        return $colors[strlen($name) % count($colors)];
    }
```suggestion protected function getRandomColor(string $name): string { $colors = config("colors"); return $colors[strlen($name) % count($colors)]; } ```

View File

@@ -4,21 +4,20 @@ declare(strict_types=1);
namespace Toby\Observers; namespace Toby\Observers;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use LasseRafn\InitialAvatarGenerator\InitialAvatar; use Toby\Helpers\UserAvatarGenerator;
use Toby\Models\User; use Toby\Models\User;
class UserObserver class UserObserver
{ {
public function __construct( public function __construct(
protected InitialAvatar $generator, protected UserAvatarGenerator $generator,
) { ) {
} }
public function created(User $user): void public function created(User $user): void
{ {
$user->avatar = $this->generateAvatar($user); $user->avatar = $this->generator->generateFor($user);
$user->save(); $user->save();
} }
@@ -26,7 +25,8 @@ class UserObserver
public function updating(User $user): void public function updating(User $user): void
{ {
if ($user->isDirty("name")) { if ($user->isDirty("name")) {
$user->avatar = $this->generateAvatar($user); Storage::delete($user->avatar);
$user->avatar = $this->generator->generateFor($user);
} }
} }
@@ -34,20 +34,4 @@ class UserObserver
{ {
Storage::delete($user->avatar); Storage::delete($user->avatar);
} }
protected function generateAvatar(User $user): string
{
$path = "avatars/{$user->id}.svg";
Storage::put($path, $this->generator->rounded()->background($this->getRandomColor())->color("#F4F8FD")->smooth()->generateSvg($user->name));
return $path;
}
protected function getRandomColor(): string
{
$colors = config("colors");
return Arr::random($colors);
}
} }