Calendar_Server::__dispatch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Description: a SOAP Calendar Server.
5
 */
6
if (!@require_once __DIR__ . '/SOAP/Server.php') {
7
    exit('You must have PEAR::SOAP installed');
8
}
9
10
if (!@require_once __DIR__ . '/Calendar/Calendar.php') {
11
    define('CALENDAR_ROOT', '../../');
12
}
13
14
/**
15
 * Class Calendar_Server.
16
 */
17
class Calendar_Server
18
{
19
    public $__dispatch_map = [];
20
    public $__typedef      = [];
21
22
    public function __construct()
23
    {
24
        $this->__dispatch_map['getMonth'] = [
25
            'in'  => ['year' => 'int', 'month' => 'int'],
26
            'out' => ['month' => '{urn:PEAR_SOAP_Calendar}Month'],
27
        ];
28
        $this->__typedef['Month']         = [
29
            'monthname' => 'string',
30
            'days'      => '{urn:PEAR_SOAP_Calendar}MonthDays',
31
        ];
32
        $this->__typedef['MonthDays']     = [['{urn:PEAR_SOAP_Calendar}Day']];
33
        $this->__typedef['Day']           = [
34
            'isFirst' => 'int',
35
            'isLast'  => 'int',
36
            'isEmpty' => 'int',
37
            'day'     => 'int',
38
        ];
39
    }
40
41
    /**
42
     * @param $methodname
43
     * @return mixed|void
44
     */
45
    public function __dispatch($methodname)
46
    {
47
        if (isset($this->__dispatch_map[$methodname])) {
48
            return $this->__dispatch_map[$methodname];
49
        }
50
    }
51
52
    /**
53
     * @param $year
54
     * @param $month
55
     *
56
     * @return array
57
     */
58
    public function getMonth($year, $month)
59
    {
60
        require_once CALENDAR_ROOT . 'Month/Weekdays.php';
61
        $Month = new Calendar_Month_Weekdays($year, $month);
62
        if (!$Month->isValid()) {
63
            $V        = $Month->getValidator();
64
            $errorMsg = '';
65
            while (false !== ($error = $V->fetch())) {
66
                $errorMsg .= $error->toString() . "\n";
67
            }
68
69
            return new Soap_fault($errorMsg, 'Client');
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Soap_fault($errorMsg, 'Client') returns the type Soap_fault which is incompatible with the documented return type array.
Loading history...
Bug introduced by
The type Soap_fault was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
70
        }
71
        $monthname = date('F Y', $Month->getTimestamp());
0 ignored issues
show
Bug introduced by
It seems like $Month->getTimestamp() can also be of type string; however, parameter $timestamp of date() does only seem to accept integer|null, maybe add an additional type check? ( Ignorable by Annotation )

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

71
        $monthname = date('F Y', /** @scrutinizer ignore-type */ $Month->getTimestamp());
Loading history...
72
        $days      = [];
73
        $Month->build();
74
        while (false !== ($Day = $Month->fetch())) {
75
            $day    = [
76
                'isFirst' => (int)$Day->isFirst(),
77
                'isLast'  => (int)$Day->isLast(),
78
                'isEmpty' => (int)$Day->isEmpty(),
79
                'day'     => (int)$Day->thisDay(),
80
            ];
81
            $days[] = $day;
82
        }
83
84
        return ['monthname' => $monthname, 'days' => $days];
85
    }
86
}
87
88
$server                    = new Soap_server();
0 ignored issues
show
Bug introduced by
The type Soap_server was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
89
$server->_auto_translation = true;
90
$calendar                  = new Calendar_Server();
91
$server->addObjectMap($calendar, 'urn:PEAR_SOAP_Calendar');
92
93
if ('POST' === mb_strtoupper($_SERVER['REQUEST_METHOD'])) {
94
    $server->service($GLOBALS['HTTP_RAW_POST_DATA']);
95
} else {
96
    require_once __DIR__ . '/SOAP/Disco.php';
97
    $disco = new SOAP_DISCO_Server($server, 'PEAR_SOAP_Calendar');
0 ignored issues
show
Bug introduced by
The type SOAP_DISCO_Server was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
98
    if (\Xmf\Request::hasVar('QUERY_STRING', 'SERVER') && 0 == strcasecmp($_SERVER['QUERY_STRING'], 'wsdl')) {
99
        header('Content-type: text/xml');
100
        echo $disco->getWSDL();
101
    } else {
102
        echo 'This is a PEAR::SOAP Calendar Server. For client try <a href="8.php">here</a><br>';
103
        echo 'For WSDL try <a href="?wsdl">here</a>';
104
    }
105
    exit;
106
}
107