Completed
Push — master ( 7905af...a20446 )
by Daniele
02:33
created

DataslangApi::transformToXml()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 20
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 20
loc 20
rs 9.4285
cc 2
eloc 10
nc 4
nop 1
1
<?php
2
3
namespace Dataslang;
4
5
use GuzzleHttp\Client;
6
7
class DataslangApi {
8
	
9
	const BASE_URI = 'http://api.dataslang';
10
	
11
	private $client = null;
0 ignored issues
show
Unused Code introduced by
The property $client 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...
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
				]
26
			]);
27
			
28
			$result = $response->getBody();
29
			
30
		} catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
31
32
		}
33
		
34
		return $result;
35
  	}
36
  	
37 View Code Duplication
  	public function transformToXml($xml){
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...
38
  		$result = null;
39
  		
40
  		try {
41
  				
42
  			$client = $this->getClient();
43
  			$response = $client->request('POST', '/xml/transform/xml', [
44
  				'form_params' => [
45
  					'xml' => urlencode($xml)
46
  				]
47
  			]);
48
  				
49
  			$result = $response->getBody();
50
  				
51
  		} catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
52
53
  		}
54
  		
55
  		return $result;
56
  	}
57
  	
58 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...
59
  		$result = null;
60
  		
61
  		try {
62
  		
63
  			$client = $this->getClient();
64
  			$response = $client->request('POST', '/xml/transform/html', [
65
				'form_params' => [
66
					'xml' => urlencode($xml),
67
					'xsl' => urlencode($xsl),
68
					'dest_path' => urlencode($dest_path)
69
				]
70
  			]);
71
  		
72
  			$result = $response->getBody();
73
  		
74
  		} catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
75
76
  		}
77
  		
78
  		return $result;
79
  	}
80
  
81
	public function setTimeout($timeout){
82
		$this->timeout = $timeout;
83
	}
84
	
85
	public function getTimeout(){
86
		return $this->timeout;
87
	}
88
	
89
	public function getBaseUri(){
90
		return self::BASE_URI;
91
	}
92
	
93
	private function getClient(){
94
		$settings = array();
95
		$settings['base_uri'] = $this->getBaseUri();
96
		$settings['timeout'] = $this->getTimeout();
97
		
98
		return new Client($settings);
99
	}
100
101
}
102