Put::prepare()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 4
c 1
b 0
f 0
nc 5
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace sylouuu\Curl\Method;
4
5
    /**
6
     * Put
7
     *
8
     * @author sylouuu
9
     * @link https://github.com/sylouuu/php-curl
10
     * @version 0.8.1
11
     * @license MIT
12
     */
13
    class Put extends \sylouuu\Curl\Curl
14
    {
15
        /**
16
         * Constructor
17
         *
18
         * @param string $url
19
         * @param array $options
20
         */
21
        public function __construct($url, $options = null)
22
        {
23
            parent::__construct($url, $options);
24
25
            $this->prepare();
26
        }
27
28
        /**
29
         * Prepare the request
30
         */
31
        public function prepare()
32
        {
33
            $this->setCurlOption(CURLOPT_CUSTOMREQUEST, 'PUT');
0 ignored issues
show
Bug introduced by
sylouuu\Curl\Method\CURLOPT_CUSTOMREQUEST of type integer is incompatible with the type sylouuu\Curl\const expected by parameter $option of sylouuu\Curl\Curl::setCurlOption(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
            $this->setCurlOption(/** @scrutinizer ignore-type */ CURLOPT_CUSTOMREQUEST, 'PUT');
Loading history...
34
35
            if (isset($this->options['data'])) {
36
                // Data
37
                $data = (isset($this->options['is_payload']) && $this->options['is_payload'] === true) ? json_encode($this->options['data']) : http_build_query($this->options['data']);
38
39
                $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
40
            }
41
        }
42
    }
43