Issues (20)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Stanza/Presence.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Nucleus - XMPP Library for PHP
4
 *
5
 * Copyright (C) 2017, Some rights reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Xmpp\Stanza;
17
18
use Kadet\Xmpp\Exception\InvalidArgumentException;
19
use Kadet\Xmpp\Jid;
20
use Kadet\Xmpp\Stanza\Presence\Show;
21
use Kadet\Xmpp\Utils\filter;
22
use Kadet\Xmpp\Xml\XmlElement;
23
24
use function Kadet\Xmpp\Utils\helper\format;
25
26
/**
27
 * Represents Presence Stanza
28
 *
29
 * @package Kadet\Xmpp\Stanza
30
 *
31
 * @property string $show     Presence show type, specifying kind of contact availability.
32
 *                            One of: available, unavailable, chat, dnd, away, xa.
33
 * @property string $status   Presence status message.
34
 * @property int    $priority Presence priority
35
 */
36
class Presence extends Stanza
37
{
38
    /**
39
     * Presence constructor.
40
     * @param array $options {
41
     *     @var Jid    $from    Jid representing "from" stanza attribute
42
     *     @var Jid    $to      Jid representing "to" stanza attribute
43
     *     @var string $id      Unique id, will be generated if omitted
44
     *     @var string $type    Stanza type
45
     *     @var string $show
46
     *     @var string status
47
     *     @var int    $priority
48
     * }
49
     */
50 13
    public function __construct(array $options = [])
51
    {
52 13
        parent::__construct('presence', $options);
53 13
    }
54
55
    /**
56
     * @return null|string
57
     */
58 4
    public function getShow()
59
    {
60 4
        return (string)$this->element('show', 'jabber:client')->innerXml // return show node content if exist
61 4
            ?? (in_array($this->type, ['available', 'unavailable']) ? $this->type : null); // or type if available
62
    }
63
64
    /**
65
     * Sets presence show. If $show is "available" or "unavailable" it sets presence type to match show kind.
66
     *
67
     * @param string $show Desired show type.
68
     */
69 6
    public function setShow(string $show = 'available')
70
    {
71 6
        if(!Show::valid($show)) {
72
            throw new InvalidArgumentException(format('$show must be one of: {possible}. {show} given.', [
73
                'possible' => implode(', ', Show::available()),
74
                'show'     => $show
75
            ]));
76
        }
77
78 6
        $predicate = filter\element('show', 'jabber:client');
79 6
        if(in_array($show, ['available', 'unavailable'])) {
80 2
            $this->remove($predicate);
81 2
            $this->type = $show;
82 2
            return;
83
        }
84
85 4
        ($this->get($predicate) ?: $this->append(new XmlElement('show', 'jabber:client')))->setContent($show);
86 4
    }
87
88
    /**
89
     * Gets presence status message.
90
     *
91
     * @return null|string
92
     */
93 1
    public function getStatus()
94
    {
95 1
        return (string)$this->element('status')->innerXml ?? null;
96
    }
97
98 1
    public function setStatus(string $status = null)
99
    {
100 1
        $predicate = filter\element('status', 'jabber:client');
101 1
        if($status === null) {
102
            $this->remove($predicate);
103
            return;
104
        }
105
106 1
        ($this->get($predicate) ?: $this->append(new XmlElement('status', 'jabber:client')))->setContent($status);
107 1
    }
108
109 1
    public function getPriority()
110
    {
111 1
        return (int)$this->element('priority')->innerXml ?? null;
112
    }
113
114 1
    public function setPriority(int $priority = null)
115
    {
116 1
        $predicate = filter\element('status', 'jabber:client');
117 1
        if(!$priority) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $priority of type null|integer is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
118
            $this->remove($predicate);
119
        }
120
121 1
        $element = $this->has($predicate)
122
            ? $this->element('status', 'jabber:client')
123 1
            : $this->append(new XmlElement('priority', 'jabber:client'));
124
125 1
        $element->setContent((string)$priority);
126 1
    }
127
128
    public static function show(string $show, string $status = null, array $options = [])
129
    {
130
        return new self(array_merge($options, [
131
            'show' => $show,
132
            'status' => $status,
133
        ]));
134
    }
135
}