mrcnpdlk/xmdb-api

View on GitHub

Showing 93 of 93 total issues

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

            if (!empty($find['movie_results']) && \count($find['movie_results']) === 1) {
                $item = $find['movie_results'][0];

                $oTitle->isAdult      = isset($item['adult']) ? (bool)$item['adult'] : false;
                $oTitle->title        = $item['title'];
Severity: Major
Found in src/Tmdb.php and 1 other location - About 1 day to fix
src/Tmdb.php on lines 128..146

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 245.

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

            } elseif (!empty($find['tv_results']) && \count($find['tv_results']) === 1) {
                $item = $find['tv_results'][0];

                $oTitle->isAdult      = isset($item['adult']) ? (bool)$item['adult'] : false;
                $oTitle->title        = $item['name'];
Severity: Major
Found in src/Tmdb.php and 1 other location - About 1 day to fix
src/Tmdb.php on lines 110..151

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 245.

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

            $oResp = $this->oClient->getAdapter()->useCache(
                function () use ($imdbId) {
                    $oCurl = new Curl();
                    $oCurl->setUserAgent(UserAgent::random());
                    $oCurl->setHeader('Accept-Language', $this->oClient->getLang());
Severity: Major
Found in src/Omdb.php and 1 other location - About 6 hrs to fix
src/Omdb.php on lines 115..139

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 215.

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

            $oResp = $this->oClient->getAdapter()->useCache(
                function () use ($title) {
                    $oCurl = new Curl();
                    $oCurl->setUserAgent(UserAgent::random());
                    $oCurl->setHeader('Accept-Language', $this->oClient->getLang());
Severity: Major
Found in src/Omdb.php and 1 other location - About 6 hrs to fix
src/Omdb.php on lines 67..91

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 215.

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

Function searchByTitleNative has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

    public function searchByTitleNative(string $title): array
    {
        try {
            /**
             * @var Title[] $answer
Severity: Minor
Found in src/Imdb.php - About 6 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 searchByTitleNative has 102 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function searchByTitleNative(string $title): array
    {
        try {
            /**
             * @var Title[] $answer
Severity: Major
Found in src/Imdb.php - About 4 hrs to fix

    Method getTvShow has 68 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getTvShow(int $id): TvShowTitle
        {
            try {
                $tData = $this->oTmdbClient
                    ->getTvApi()
    Severity: Major
    Found in src/Tmdb.php - About 2 hrs to fix

      File Tmdb.php has 279 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      /**
       * xMDB-API
       *
       * Copyright © 2017 pudelek.org.pl
      Severity: Minor
      Found in src/Tmdb.php - About 2 hrs to fix

        Method getByImdbId has 60 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getByImdbId(string $imdbId = null)
            {
                try {
                    $this->oLog->info(sprintf('Searching: %s', $imdbId));
                    if ($imdbId === null || $imdbId === '') {
        Severity: Major
        Found in src/Tmdb.php - About 2 hrs to fix

          Method getMovie has 57 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getMovie(int $id): Model\Tmdb\Movie\Title
              {
                  try {
                      $tData                = $this->oTmdbClient->getMoviesApi()->getMovie($id, [
                          'language'      => $this->oClient->getLang(),
          Severity: Major
          Found in src/Tmdb.php - About 2 hrs to fix

            File Imdb.php has 255 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            <?php
            /**
             * xMDB-API
             *
             * Copyright © 2017 pudelek.org.pl
            Severity: Minor
            Found in src/Imdb.php - About 2 hrs to fix

              Method getRating has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getRating(string $imdbId): Rating
                  {
                      try {
                          $searchUrl = 'http://p.media-imdb.com/static-content/documents/v1/title/'
                              . $imdbId
              Severity: Minor
              Found in src/Imdb.php - About 1 hr to fix

                The class Title has 20 fields. Consider redesigning Title to keep the number of fields under 15.
                Open

                class Title
                {
                    /**
                     * @var string
                     */
                Severity: Minor
                Found in src/Model/Title.php by phpmd

                TooManyFields

                Since: 0.1

                Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

                Example

                class Person {
                   protected $one;
                   private $two;
                   private $three;
                   [... many more fields ...]
                }

                Source https://phpmd.org/rules/codesize.html#toomanyfields

                The class Title has 26 fields. Consider redesigning Title to keep the number of fields under 15.
                Open

                class Title
                {
                    /**
                     * @var integer
                     */
                Severity: Minor
                Found in src/Model/Tmdb/Movie/Title.php by phpmd

                TooManyFields

                Since: 0.1

                Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

                Example

                class Person {
                   protected $one;
                   private $two;
                   private $three;
                   [... many more fields ...]
                }

                Source https://phpmd.org/rules/codesize.html#toomanyfields

                The class Title has 28 fields. Consider redesigning Title to keep the number of fields under 15.
                Open

                class Title
                {
                    /**
                     * @var integer
                     */
                Severity: Minor
                Found in src/Model/Tmdb/TvShow/Title.php by phpmd

                TooManyFields

                Since: 0.1

                Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

                Example

                class Person {
                   protected $one;
                   private $two;
                   private $three;
                   [... many more fields ...]
                }

                Source https://phpmd.org/rules/codesize.html#toomanyfields

                The class Info has 18 fields. Consider redesigning Info to keep the number of fields under 15.
                Open

                class Info
                {
                    /**
                     * @var string
                     */
                Severity: Minor
                Found in src/Model/Imdb/Info.php by phpmd

                TooManyFields

                Since: 0.1

                Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

                Example

                class Person {
                   protected $one;
                   private $two;
                   private $three;
                   [... many more fields ...]
                }

                Source https://phpmd.org/rules/codesize.html#toomanyfields

                Method searchByTitle has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function searchByTitle(string $title)
                    {
                        try {
                            /**
                             * @var Title[] $answer
                Severity: Minor
                Found in src/Tmdb.php - About 1 hr to fix

                  Method create has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static function create(\stdClass $oData)
                      {
                          $oTitle                   = new static();
                          $oTitle->title            = $oData->Title;
                          $oTitle->titleOrg         = $oData->Title;
                  Severity: Minor
                  Found in src/Model/Omdb/Title.php - About 1 hr to fix

                    Method getByImdbId has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function getByImdbId(string $imdbId, Ratio $oRatio = null)
                        {
                            try {
                                $oResp = $this->oClient->getAdapter()->useCache(
                                    function () use ($imdbId) {
                    Severity: Minor
                    Found in src/Omdb.php - About 1 hr to fix

                      Method searchByTitleApi has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function searchByTitleApi(string $title): array
                          {
                              try {
                                  $answer = [];
                                  $tList  = $this->getApiTitleSearch()->search($title, [
                      Severity: Minor
                      Found in src/Imdb.php - About 1 hr to fix
                        Severity
                        Category
                        Status
                        Source
                        Language