Glossary   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 46
loc 46
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A download() 5 5 1
A upload() 15 15 2

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
 * Crowdin API implementation in PHP.
4
 *
5
 * @copyright  Copyright (C) 2016 Nikolai Plath (elkuku)
6
 * @license    WTFPL - See license.txt
7
 */
8
9
namespace ElKuKu\Crowdin\Package;
10
11
use ElKuKu\Crowdin\Package;
12
13
use Psr\Http\Message\ResponseInterface;
14
15
/**
16
 * Class Glossary
17
 *
18
 * @since  1.0.5
19
 */
20 View Code Duplication
Class Glossary extends Package
0 ignored issues
show
Duplication introduced by
This class 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...
21
{
22
	/**
23
	 * Download Crowdin project glossaries as TBX file.
24
	 *
25
	 * @param   boolean  $includeAssigned  Defines whether the assigned glossaries should be included in downloaded TBX file.
26
	 *                                     Acceptable values are: 0, 1.
27
	 *                                     Default is 1.
28
	 *
29
	 * @since 1.0.5
30
	 * @see   https://crowdin.com/page/api/download-glossary
31
	 *
32
	 * @return ResponseInterface
33
	 */
34 1
	public function download(bool $includeAssigned = true) : ResponseInterface
35
	{
36 1
		return $this->getHttpClient()
37 1
			->get($this->getBasePath('download-glossary') . '&include_assigned=' . (int) $includeAssigned);
38
	}
39
40
	/**
41
	 * Upload your Translation Memory for Crowdin Project in TMX file format.
42
	 *
43
	 * @param   string  $file  Full path to file to upload.
44
	 *
45
	 * @since 1.0.5
46
	 * @see   https://crowdin.com/page/api/upload-glossary
47
	 *
48
	 * @return ResponseInterface
49
	 */
50 2
	public function upload(string $file) : ResponseInterface
51
	{
52 2
		if (false === file_exists($file))
53
		{
54 1
			throw new \UnexpectedValueException('File not found for upload');
55
		}
56
57
		$data = [[
58 1
			'name'     => 'file',
59 1
			'contents' => fopen($file, 'r')
60
		]];
61
62 1
		return $this->getHttpClient()
63 1
			->post($this->getBasePath('upload-glossary'), ['multipart' => $data]);
64
	}
65
}
66