Completed
Push — master ( 2ad0de...2fd600 )
by Levan
03:06
created

TranslationTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 55 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 22
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testTranslationEquality() 11 11 2
A testUTF16Translation() 11 11 2
A testRawResponse() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Stichoza\GoogleTranslate\Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use Stichoza\GoogleTranslate\GoogleTranslate;
7
8
class TranslationTest extends TestCase
9
{
10
    public $tr;
11
12
    public function setUp()
13
    {
14
        $this->tr = new GoogleTranslate();
15
    }
16
17 View Code Duplication
    public function testTranslationEquality()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
    {
19
        try {
20
            $resultOne = GoogleTranslate::trans('Hello', 'ka', 'en');
21
        } catch (\ErrorException $e) {
0 ignored issues
show
Bug introduced by
The class ErrorException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
22
            $resultOne = null;
23
        }
24
        $resultTwo = $this->tr->setSource('en')->setTarget('ka')->translate('Hello');
25
26
        $this->assertEquals($resultOne, $resultTwo, 'გამარჯობა');
27
    }
28
29 View Code Duplication
    public function testUTF16Translation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31
        try {
32
            $resultOne = GoogleTranslate::trans('yes 👍🏽', 'de', 'en');
33
        } catch (\ErrorException $e) {
0 ignored issues
show
Bug introduced by
The class ErrorException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
34
            $resultOne = null;
35
        }
36
        $resultTwo = $this->tr->setSource('en')->setTarget('de')->translate('yes 👍🏽');
37
38
        $this->assertEquals($resultOne, $resultTwo, 'ja 👍🏽');
39
    }
40
41
    public function testRawResponse()
42
    {
43
        $rawResult = $this->tr->getResponse('cat');
44
45
        $this->assertTrue(is_array($rawResult), 'Method getResponse() should return an array.');
46
    }
47
}
48