Memory::upload()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 15
loc 15
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 2
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