EscolaLMS/H5P

View on GitHub
src/Repositories/H5PRepository.php

Summary

Maintainability
F
4 days
Test Coverage
B
89%

File H5PRepository.php has 678 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace EscolaLms\HeadlessH5P\Repositories;

use EscolaLms\HeadlessH5P\Exceptions\H5PException;
Severity: Major
Found in src/Repositories/H5PRepository.php - About 1 day to fix

    H5PRepository has 65 functions (exceeds 20 allowed). Consider refactoring.
    Confirmed

    class H5PRepository implements H5PFrameworkInterface
    {
    
        private H5PLibraryLanguageRepositoryContract $h5PLibraryLanguageRepository;
    
    
    Severity: Major
    Found in src/Repositories/H5PRepository.php - About 1 day to fix

      Function fixContentParamsMetadataLibraryTitle has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          private function fixContentParamsMetadataLibraryTitle($content)
          {
              $defaultTitle = isset($this->mainData['title']) ? $this->mainData['title'] : 'New Content (from file)';
      
              if (is_array($content['library'])) {
      Severity: Minor
      Found in src/Repositories/H5PRepository.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 fixContentParamsMetadataLibraryTitle has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function fixContentParamsMetadataLibraryTitle($content)
          {
              $defaultTitle = isset($this->mainData['title']) ? $this->mainData['title'] : 'New Content (from file)';
      
              if (is_array($content['library'])) {
      Severity: Major
      Found in src/Repositories/H5PRepository.php - About 2 hrs to fix

        Method saveLibraryUsage has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function saveLibraryUsage($contentId, $librariesInUse)
            {
                $contentLibraries = array_map(function ($value) use ($contentId) {
                    $contentLibrary = H5PContentLibrary::query()
                        ->where([
        Severity: Minor
        Found in src/Repositories/H5PRepository.php - About 1 hr to fix

          Method replaceContentTypeCache has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function replaceContentTypeCache($contentTypeCache)
              {
                  $data = [];
                  foreach ($contentTypeCache->contentTypes as $ct) {
                     $data[] = [
          Severity: Minor
          Found in src/Repositories/H5PRepository.php - About 1 hr to fix

            Method saveLibraryData has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Confirmed

                public function saveLibraryData(&$libraryData, $new = true)
                {
                    $library = [
                        'name' => $libraryData['machineName'],
                        'title' => $libraryData['title'],
            Severity: Minor
            Found in src/Repositories/H5PRepository.php - About 1 hr to fix

              Method fetchExternalData has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function fetchExternalData($url, $data = null, $blocking = true, $stream = null, $fullData = false, $headers = [], $files = [], $method = 'POST')
                  {
                      @set_time_limit(0);
                      $options = [
                          'timeout'  => !empty($blocking) ? 30 : 0.01,
              Severity: Minor
              Found in src/Repositories/H5PRepository.php - About 1 hr to fix

                Method fetchExternalData has 8 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    public function fetchExternalData($url, $data = null, $blocking = true, $stream = null, $fullData = false, $headers = [], $files = [], $method = 'POST')
                Severity: Major
                Found in src/Repositories/H5PRepository.php - About 1 hr to fix

                  Function fetchExternalData has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function fetchExternalData($url, $data = null, $blocking = true, $stream = null, $fullData = false, $headers = [], $files = [], $method = 'POST')
                      {
                          @set_time_limit(0);
                          $options = [
                              'timeout'  => !empty($blocking) ? 30 : 0.01,
                  Severity: Minor
                  Found in src/Repositories/H5PRepository.php - About 45 mins 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

                  Avoid too many return statements within this method.
                  Open

                          return true;
                  Severity: Major
                  Found in src/Repositories/H5PRepository.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return true;
                    Severity: Major
                    Found in src/Repositories/H5PRepository.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return false;
                      Severity: Major
                      Found in src/Repositories/H5PRepository.php - About 30 mins to fix

                        Function additionalTranslations has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            private function additionalTranslations(array $libraryLanguages, H5PLibrary $library): array
                            {
                                $additionalLanguageCodes = ['pl'];
                                foreach ($additionalLanguageCodes as $languageCode) {
                                    if (!isset($libraryLanguages[$languageCode])) {
                        Severity: Minor
                        Found in src/Repositories/H5PRepository.php - About 25 mins 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

                        There are no issues that match your filters.

                        Category
                        Status