ar_connect_oauthClient::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
	ar_pinp::allow('ar_connect_oauth');
3
	ar_pinp::allow('ar_connect_oauthClient');
4
5
	class ar_connect_oauth extends arBase {
6
7
		public static function getSBS( $method, $uri, $request_parameters = array() ) {
8
			if ( function_exists('oauth_get_sbs') ) {
9
				return oauth_get_sbs( $method, $uri, $request_parameters );
10
			} else {
11
				return ar_error::raiseError( 'OAuth PECL extension not installed.', ar_exceptions::CONFIGURATION_ERROR );
12
			}
13
		}
14
15
		public static function client( $consumer_key, $consumer_secret, $signature_method = OAUTH_SIG_METHOD_HMACSHA1, $auth_type = 0 ) {
16
			return new ar_connect_oauthClient( $consumer_key, $consumer_secret, $signature_method, $auth_type );
17
		}
18
19
	}
20
21
	class ar_connect_oauthClient extends arWrapper implements ar_httpClient {
22
23
		public function __construct( $consumer_key, $consumer_secret, $signature_method= OAUTH_SIG_METHOD_HMACSHA1, $auth_type = 0 ) {
24
			if ( !class_exists('OAuth') ) {
25
				return ar_error::raiseError( 'OAuth PECL extension not installed', ar_exceptions::CONFIGURATION_ERROR );
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
26
			}
27
			$oauth = new OAuth( $consumer_key, $consumer_secret, $signature_method, $auth_type );
28
			$oauth->setRequestEngine(OAUTH_REQENGINE_STREAMS);
29
			parent::__construct( $oauth );
30
		}
31
32
		public function send( $type, $url, $request = null, $options = array() ) {
33
			if ( is_string($options['header']) ) {
34
				$headers = preg_split( '\r\n', $options['header'] );
35
			} else {
36
				$headers = (array) $options['header'];
37
			}
38
			switch( $type ) {
39
				case 'GET' : $type = OAUTH_HTTP_METHOD_GET;
40
				break;
41
				case 'POST' : $type = OAUTH_HTTP_METHOD_POST;
42
				break;
43
				case 'PUT' : $type = OAUTH_HTTP_METHOD_PUT;
44
				break;
45
				case 'DELETE' : $type = OAUTH_HTTP_METHOD_DELETE;
46
				break;
47
			}
48
			try {
49
				if ( $this->wrapped->fetch( (string) $url, $request, $type, $headers ) ) {
50
					return $this->wrapped->getLastResponse();
51
				} else {
52
					return ar_error::raiseError( 'OAuth fetch failed', ar_exceptions::UNKNOWN_ERROR );
53
				}
54
			} catch( Exception $e ) {
55
				return ar_error::raiseError( $e->getMessage(), $e->getCode() );
56
			}
57
		}
58
59
		public function get( $url, $request = null, $options = array() ) {
60
			return $this->send( 'GET', (string) $url, $request, $options );
61
		}
62
63
		public function post( $url, $request = null, $options = array() ) {
64
			return $this->send( 'POST', (string) $url, $request, $options );
65
		}
66
67
		public function put( $url, $request = null, $options = array() ) {
68
			return $this->send( 'PUT', (string) $url, $request, $options );
69
		}
70
71
		public function delete( $url, $request = null, $options = array() ) {
72
			return $this->send( 'DELETE', (string) $url, $request, $options );
73
		}
74
75
		public function headers( $headers ) {
76
			if (is_array($headers)) {
77
				$headers = join("\r\n", $headers);
78
			}
79
			if ($this->options['header'] && substr( $this->options['header'], -2 )!=="\r\n") {
0 ignored issues
show
Documentation introduced by
The property options does not exist on object<ar_connect_oauthClient>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
80
				$this->options['header'] .= "\r\n";
0 ignored issues
show
Documentation introduced by
The property options does not exist on object<ar_connect_oauthClient>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
81
			}
82
			$this->options['header'] .= $headers;
0 ignored issues
show
Documentation introduced by
The property options does not exist on object<ar_connect_oauthClient>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
83
			return $this;
84
		}
85
86
	}
87