pixelfed/pixelfed

View on GitHub

Showing 1,558 of 1,561 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        $res = $res->map(function ($status) use ($pid, $napi) {
            $account = $napi ? AccountService::get($status->profile_id, true) : AccountService::getMastodon($status->profile_id, true);
            if (! $account) {
                return false;
            }
Severity: Major
Found in app/Http/Controllers/Api/ApiV1Controller.php and 1 other location - About 3 hrs to fix
app/Http/Controllers/Api/ApiV1Controller.php on lines 3280..3295

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 159.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 4 locations. Consider refactoring.
Open

        $requests = function ($audience) use ($client, $activity, $profile, $payload, $userAgent) {
            foreach ($audience as $url) {
                $headers = HttpSignature::sign($profile, $url, $activity, [
                    'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
                    'User-Agent' => $userAgent,
Severity: Major
Found in app/Console/Commands/UserAccountDelete.php and 3 other locations - About 3 hrs to fix
app/Jobs/ProfilePipeline/ProfileMigrationDeliverMoveActivityPipeline.php on lines 108..126
app/Jobs/StatusPipeline/StatusActivityPubDeliver.php on lines 117..135
app/Jobs/StatusPipeline/StatusLocalUpdateActivityPubDeliverPipeline.php on lines 97..115

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 159.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

            Route::group(['prefix' => 'collections'], function () use($middleware) {
                Route::get('accounts/{id}', 'CollectionController@getUserCollections')->middleware($middleware);
                Route::get('items/{id}', 'CollectionController@getItems')->middleware($middleware);
                Route::get('view/{id}', 'CollectionController@getCollection')->middleware($middleware);
                Route::post('add', 'CollectionController@storeId')->middleware($middleware);
Severity: Major
Found in routes/api.php and 1 other location - About 3 hrs to fix
routes/api.php on lines 128..136

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 159.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 4 locations. Consider refactoring.
Open

        $requests = function($audience) use ($client, $activity, $profile, $payload, $userAgent) {
            foreach($audience as $url) {
                $headers = HttpSignature::sign($profile, $url, $activity, [
                    'Content-Type'    => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
                    'User-Agent'    => $userAgent,
app/Console/Commands/UserAccountDelete.php on lines 91..109
app/Jobs/ProfilePipeline/ProfileMigrationDeliverMoveActivityPipeline.php on lines 108..126
app/Jobs/StatusPipeline/StatusActivityPubDeliver.php on lines 117..135

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 159.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        $res = $res->map(function ($like) use ($pid, $napi) {
            $account = $napi ? AccountService::get($like->profile_id, true) : AccountService::getMastodon($like->profile_id, true);
            if (! $account) {
                return false;
            }
Severity: Major
Found in app/Http/Controllers/Api/ApiV1Controller.php and 1 other location - About 3 hrs to fix
app/Http/Controllers/Api/ApiV1Controller.php on lines 3179..3193

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 159.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Status has 31 functions (exceeds 20 allowed). Consider refactoring.
Open

class Status extends Model
{
    use HasSnowflakePrimary, SoftDeletes;

    /**
Severity: Minor
Found in app/Status.php - About 3 hrs to fix

    Method mediaUpload has 95 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function mediaUpload(Request $request)
        {
            abort_if(! $request->user() || ! $request->user()->token(), 403);
            abort_unless($request->user()->tokenCan('write'), 403);
    
    
    Severity: Major
    Found in app/Http/Controllers/Api/ApiV1Controller.php - About 3 hrs to fix

      File SearchController.php has 325 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      namespace App\Http\Controllers;
      
      use App\Hashtag;
      Severity: Minor
      Found in app/Http/Controllers/SearchController.php - About 3 hrs to fix

        Method moderatePost has 94 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function moderatePost(Request $request, $id)
            {
                abort_if(! $request->user() || ! $request->user()->token(), 403);
                abort_if($request->user()->is_admin != true, 403);
                abort_unless($request->user()->tokenCan('admin:write'), 403);
        Severity: Major
        Found in app/Http/Controllers/Api/ApiV1Dot1Controller.php - About 3 hrs to fix

          Function handleCreateActivity has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
          Open

              public function handleCreateActivity()
              {
                  $activity = $this->payload['object'];
                  if(config('autospam.live_filters.enabled')) {
                      $filters = config('autospam.live_filters.filters');
          Severity: Minor
          Found in app/Util/ActivityPub/Inbox.php - About 3 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method get has 93 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function get()
              {
                  return [
                      1 => [
                          "id" => 1,
          Severity: Major
          Found in app/Util/Media/License.php - About 3 hrs to fix

            Method handleUndoActivity has 92 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function handleUndoActivity()
                {
                    $actor = $this->payload['actor'];
                    $profile = self::actorFirstOrCreate($actor);
                    $obj = $this->payload['object'];
            Severity: Major
            Found in app/Util/ActivityPub/Inbox.php - About 3 hrs to fix

              Method reportsHandleSpamAction has 92 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function reportsHandleSpamAction($appeal, $action)
                  {
                      $meta = json_decode($appeal->meta);
              
                      if ($action == 'mark-read') {
              Severity: Major
              Found in app/Http/Controllers/Admin/AdminReportController.php - About 3 hrs to fix

                Method instance has 92 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function instance(Request $request)
                    {
                        $contact = Cache::remember('api:v1:instance-data:contact', 604800, function () {
                            if(config_cache('instance.admin.pid')) {
                                return AccountService::getMastodon(config_cache('instance.admin.pid'), true);
                Severity: Major
                Found in app/Http/Controllers/Api/ApiV2Controller.php - About 3 hrs to fix

                  Method accountNotifications has 92 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function accountNotifications(Request $request)
                      {
                          abort_if(! $request->user() || ! $request->user()->token(), 403);
                          abort_unless($request->user()->tokenCan('read'), 403);
                  
                  
                  Severity: Major
                  Found in app/Http/Controllers/Api/ApiV1Controller.php - About 3 hrs to fix

                    Method validate has 91 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public static function validate($payload)
                        {
                            $valid = Validator::make($payload, [
                                '@context' => 'required',
                                'id' => 'required|string|url',
                    Severity: Major
                    Found in app/Util/ActivityPub/Validator/UpdatePersonValidator.php - About 3 hrs to fix

                      Method inAppRegistration has 90 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function inAppRegistration(Request $request)
                          {
                              abort_if($request->user(), 404);
                              abort_unless((bool) config_cache('pixelfed.open_registration'), 404);
                              abort_unless((bool) config_cache('pixelfed.allow_app_registration'), 404);
                      Severity: Major
                      Found in app/Http/Controllers/Api/ApiV1Dot1Controller.php - About 3 hrs to fix

                        Method mediaUpload has 90 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public function mediaUpload(Request $request)
                            {
                                $this->validate($request, [
                                    'file'      => function() {
                                        return [
                        Severity: Major
                        Found in app/Http/Controllers/DirectMessageController.php - About 3 hrs to fix

                          Method transform has 90 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function transform(Status $status)
                              {
                                  $mentions = $status->mentions->map(function ($mention) {
                                      $webfinger = $mention->emailUrl();
                                      $name = Str::startsWith($webfinger, '@') ?
                          Severity: Major
                          Found in app/Transformer/ActivityPub/Verb/Question.php - About 3 hrs to fix

                            Function settingsApiUpdateUsersType has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public function settingsApiUpdateUsersType($request)
                                {
                                    $this->validate($request, [
                                        'require_email_verification' => 'required',
                                        'enforce_account_limit' => 'required',
                            Severity: Minor
                            Found in app/Http/Controllers/Admin/AdminSettingsController.php - About 3 hrs to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Severity
                            Category
                            Status
                            Source
                            Language