Memory   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 4
Bugs 0 Features 1
Metric Value
wmc 3
c 4
b 0
f 1
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 Memory
17
 *
18
 * @since  1.0.5
19
 */
20 View Code Duplication
Class Memory 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 Translation Memory as TMX file.
24
	 *
25
	 * @param   boolean  $includeAssigned  Defines whether the assigned TMs should be included in downloaded TMX 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-tm
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-tm') . '&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-tm
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-tm'), ['multipart' => $data]);
64
	}
65
}
66