DataslangApi   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 103
Duplicated Lines 66.02 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 11
c 7
b 0
f 0
lcom 1
cbo 1
dl 68
loc 103
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 22 22 2
A transformToXml() 23 23 2
A transformToHtml() 23 23 2
A setTimeout() 0 3 1
A getTimeout() 0 3 1
A getBaseUri() 0 3 1
A getClient() 0 11 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
namespace Dataslang;
4
5
use GuzzleHttp\Client;
6
7
class DataslangApi {
8
	
9
	const BASE_URI = 'http://api.dataslang.com';
10
	
11
	private $client = null;
12
	private $settings = array();
0 ignored issues
show
Unused Code introduced by
The property $settings is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
13
	private $timeout = 7;
14
15 View Code Duplication
	public function validate($xml, $xsd){
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...
16
		$result = null;
17
18
		try {
19
			
20
			$client = $this->getClient();
21
			$response = $client->request('POST', '/xml/validate', [
22
				'form_params' => [
23
					'xml' => urlencode($xml),
24
					'xsd' => urlencode($xsd),
25
					'response-type' => urlencode('txt')
26
				]
27
			]);
28
			
29
			$result = $response->getBody();
30
			
31
		} catch (\Exception $e) {
32
			$result = $e->getMessage();
33
		}
34
		
35
		return $result;
36
  	}
37
  	
38 View Code Duplication
  	public function transformToXml($xml, $xsl, $dest_path){
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...
39
  		$result = null;
40
  		
41
  		try {
42
  				
43
  			$client = $this->getClient();
44
  			$response = $client->request('POST', '/xml/transform/xml', [
45
  				'form_params' => [
46
  					'xml' => urlencode($xml),
47
  					'xsl' => urlencode($xsl),
48
  					'dest_path' => urlencode($dest_path),
49
  					'response-type' => urlencode('txt')
50
  				]
51
  			]);
52
  				
53
  			$result = $response->getBody();
54
  				
55
  		} catch (\Exception $e) {
56
  			$result = $e->getMessage();
57
  		}
58
  		
59
  		return $result;
60
  	}
61
  	
62 View Code Duplication
  	public function transformToHtml($xml, $xsl, $dest_path){
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...
63
  		$result = null;
64
  		
65
  		try {
66
  		
67
  			$client = $this->getClient();
68
  			$response = $client->request('POST', '/xml/transform/html', [
69
				'form_params' => [
70
					'xml' => urlencode($xml),
71
					'xsl' => urlencode($xsl),
72
					'dest_path' => urlencode($dest_path),
73
					'response-type' => urlencode('txt')
74
				]
75
  			]);
76
  		
77
  			$result = $response->getBody();
78
  		
79
  		} catch (\Exception $e) {
80
  			$result = $e->getMessage();
81
  		}
82
  		
83
  		return $result;
84
  	}
85
  
86
	public function setTimeout($timeout){
87
		$this->timeout = $timeout;
88
	}
89
	
90
	public function getTimeout(){
91
		return $this->timeout;
92
	}
93
	
94
	public function getBaseUri(){
95
		return self::BASE_URI;
96
	}
97
	
98
	private function getClient(){
99
		if ($this->client === null){
100
			$settings = array();
101
			$settings['base_uri'] = $this->getBaseUri();
102
			$settings['timeout'] = $this->getTimeout();
103
		
104
			$this->client = new Client($settings);
105
		}
106
		
107
		return $this->client;
108
	}
109
}
110