biurad/php-git-scm

View on GitHub

Showing 24 of 24 total issues

File Repository.php has 458 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php declare(strict_types=1);

/*
 * This file is part of Biurad opensource projects.
 *
Severity: Minor
Found in src/Repository.php - About 7 hrs to fix

    Repository has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Repository
    {
        private float $timeout = 600.0;
        private string $command = 'git';
        private int $exitCode = 0;
    Severity: Minor
    Found in src/Repository.php - About 4 hrs to fix

      Function getData has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

          private function getData(string $name): mixed
          {
              if (!isset($this->data[$name])) {
                  $o = $this->content ?? $this->repository->run('cat-file', ['commit', $this->__toString()]);
      
      
      Severity: Minor
      Found in src/Commit.php - About 4 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

      Function runConcurrent has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          public function runConcurrent(array $commands, callable $callback = null, bool $exitOnFailure = true, string $cwd = null): array
          {
              $outputs = [];
              $this->concurrency = 0;
      
      
      Severity: Minor
      Found in src/Repository.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

      Function getBranch has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getBranch(string $revision = 'HEAD'): Branch|array|null
          {
              $o = $this->run('branch', ['--points-at', $revision, '--format=%(refname:short) %(objectname)']);
      
              if (empty($o) || 0 !== $this->exitCode) {
      Severity: Minor
      Found in src/Repository.php - About 2 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 runConcurrent has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function runConcurrent(array $commands, callable $callback = null, bool $exitOnFailure = true, string $cwd = null): array
          {
              $outputs = [];
              $this->concurrency = 0;
      
      
      Severity: Minor
      Found in src/Repository.php - About 1 hr to fix

        Function getConfig has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public function getConfig(string $key = null, string|int|float|bool $default = null): mixed
            {
                $resolve = fn (string $v) => 'true' === $v ? true : ('false' === $v ? false : (\is_numeric($v) ? (int) $v : $v));
        
                if (null === $key) {
        Severity: Minor
        Found in src/Repository.php - About 1 hr 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

        Function getReferences has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public function getReferences(): array
            {
                $o = $this->run('show-ref');
        
                if (empty($o) || 0 !== $this->exitCode) {
        Severity: Minor
        Found in src/Repository.php - About 1 hr 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

        Function getBranches has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            public function getBranches(): array
            {
                $o = $this->run('branch', ['-a', '--format=%(refname:short) %(objectname)']);
        
                if (empty($o) || 0 !== $this->exitCode) {
        Severity: Minor
        Found in src/Repository.php - About 1 hr 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

        Function getReferences has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            public function getReferences(): array
            {
                $o = $this->repository->run('for-each-ref', ['--contains', $this->__toString(), '--format=%(refname) %(objectname)']);
        
                if (empty($o) || 0 !== $this->repository->getExitCode()) {
        Severity: Minor
        Found in src/Commit.php - About 1 hr 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

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

                if (!isset($this->cache[$i = \md5($o)])) {
                    foreach (\explode("\n", $o) as $line) {
                        if (!empty($line)) {
                            [$tag, $hash] = \explode(' ', $line, 2);
                            $this->cache[$i][] = new Tag($this, 'refs/tags/'.$tag, $hash);
        Severity: Major
        Found in src/Repository.php and 1 other location - About 1 hr to fix
        src/Repository.php on lines 395..402

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

        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

                if (!isset($this->cache[$i = \md5($o)])) {
                    foreach (\explode("\n", $o) as $line) {
                        if (!empty($line)) {
                            [$tag, $hash] = \explode(' ', $line, 2);
                            $this->cache[$i][] = new Tag($this, 'refs/tags/'.$tag, $hash);
        Severity: Major
        Found in src/Repository.php and 1 other location - About 1 hr to fix
        src/Repository.php on lines 368..375

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

        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

        Method getData has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function getData(string $name): mixed
            {
                if (!isset($this->data[$name])) {
                    $o = $this->content ?? $this->repository->run('cat-file', ['commit', $this->__toString()]);
        
        
        Severity: Minor
        Found in src/Commit.php - About 1 hr to fix

          Method commit has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function commit(CommitNew|Commit\Message $commit, array $args = [], string $cwd = null): self
              {
                  if ($commit instanceof Commit\Message) {
                      $msg = $commit->__toString();
                      $msg = !empty($msg) ? ['-m', $msg] : ['--allow-empty-message'];
          Severity: Minor
          Found in src/Repository.php - About 1 hr to fix

            Function commit has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                public function commit(CommitNew|Commit\Message $commit, array $args = [], string $cwd = null): self
                {
                    if ($commit instanceof Commit\Message) {
                        $msg = $commit->__toString();
                        $msg = !empty($msg) ? ['-m', $msg] : ['--allow-empty-message'];
            Severity: Minor
            Found in src/Repository.php - About 1 hr 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

            Function doInitialize has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function doInitialize(): void
                {
                    if ($this->initialized) {
                        return;
                    }
            Severity: Minor
            Found in src/Commit/Tree.php - About 1 hr 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

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

                public function getTag(string $revision = 'HEAD'): Tag|array|null
                {
                    $o = $this->run('tag', ['--points-at', $revision, '--format=%(refname:short) %(objectname)']);
            
                    if (empty($o) || 0 !== $this->exitCode) {
            Severity: Minor
            Found in src/Repository.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

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

                public function getUntrackedFiles(bool $staged = false): array
                {
                    $o = $this->run('status', ['--porcelain', '-uall', $staged ? '-s' : '--untracked-files=all']);
            
                    if (empty($o) || 0 !== $this->exitCode) {
            Severity: Minor
            Found in src/Repository.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

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

                public function getTags(): array
                {
                    $o = $this->run('tag', ['--sort=-creatordate', '--format=%(refname:short) %(objectname)']);
            
                    if (empty($o) || 0 !== $this->exitCode) {
            Severity: Minor
            Found in src/Repository.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

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

                public function getSize(bool $real = false): int
                {
                    if ($real) {
                        if (0 === ($totalBytes = &$this->cache['size'] ?? 0)) {
                            $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getGitPath(), \FilesystemIterator::SKIP_DOTS));
            Severity: Minor
            Found in src/Repository.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

            Severity
            Category
            Status
            Source
            Language