Skip to content

Instantly share code, notes, and snippets.

@MuhammadQuran17
Created November 12, 2025 07:01
Show Gist options
  • Select an option

  • Save MuhammadQuran17/468ce027efc9e82549a51aee313c88a1 to your computer and use it in GitHub Desktop.

Select an option

Save MuhammadQuran17/468ce027efc9e82549a51aee313c88a1 to your computer and use it in GitHub Desktop.
Task to refactoring PHP code

How will you refactor this PHP code block? Use this as helper

<?php

namespace NOTIMPORTANT_NOW;


class NOTIMPORTANT_NOW extends NOTIMPORTANT_NOW
{

    public function map(array $data): array
    {
        return $this->mapWithCondition(
            $data,
            // TODO: Refacoring needed here
            readonlyCondition: fn ($row) => ( in_array($row['readonly'], config('User::user-management.roles.readonly')) || $row['super'] ) || $row['access_status'] === config('User::upload.access_statuses.deleted')
        );
    }
}
@temurbek-zarifov1214
Copy link

<?php

namespace NOTIMPORTANT_NOW;


class NOTIMPORTANT_NOW extends NOTIMPORTANT_NOW
{

    public function map(array $data): array
    {
        return $this->mapWithCondition(
            $data,
            readonlyCondition: fn ($row) => ( in_array($row['readonly'], $this->getReadOnlyUsers()) || $row['super'] ) || $row['access_status'] ===$this->getDeletedOnlyUsers());
    }

   function getReadOnlyUsers(): array
    {
        return config('User::user-management.roles.readonly', []);
    }
function getDeletedOnlyUsers(): string|array
    {
        return config('User::upload.access_statuses.deleted', []);
    }

}

@MuhammadQuran17
Copy link
Author

  1. Wrong. Very hard to read this code. Refactor better please, better functions.
  2. And make sure that code is formatted properly, because I see now it is ugly))) PSR12 violations
image

Please fix these 2 comments

@MuhammadQuran17
Copy link
Author

write code like

<?php
$a = 1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment