Completed
Push — master ( 24a68b...bc84ac )
by Thomas
22:37 queued 09:54
created

Lock::getOwner()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Thomas Müller <[email protected]>
4
 * @copyright Copyright (c) 2018, ownCloud GmbH
5
 * @license AGPL-3.0
6
 *
7
 * This code is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License, version 3,
9
 * as published by the Free Software Foundation.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License, version 3,
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
18
 */
19
20
namespace OC\Lock\Persistent;
21
22
use OCP\AppFramework\Db\Entity;
23
use OCP\Lock\Persistent\ILock;
24
25
/**
26
 * Class Lock
27
 *
28
 * @method string getTokenHash()
29
 * @method string getPath()
30
 * @method string getOwnerAccountId()
31
 *
32
 * @method setFileId(int $fileId)
33
 * @method setCreatedAt(int $timestamp)
34
 * @method setTimeout(int $timeout)
35
 * @method setScope(int $scope)
36
 * @method setDepth(int $depth)
37
 *
38
 * @package OC\Lock\Persistent
39
 */
40
class Lock extends Entity implements ILock {
41
42
	/** @var int BIGINT - foreign key to oc_filecache.fileid */
43
	protected $fileId;
44
	/** @var string - plain text field as transmitted by clients */
45
	protected $owner;
46
	/** @var int - seconds of lock life time */
47
	protected $timeout;
48
	/** @var int - unix timestamp when lock was created */
49
	protected $createdAt;
50
	/** @var string - uuid in WebDAV */
51
	protected $token;
52
	/** @var string - md5 of token */
53
	protected $tokenHash;
54
	/** @var int - LOCK_SCOPE_EXCLUSIVE or LOCK_SCOPE_SHARED */
55
	protected $scope;
56
	/** @var int: 0, 1 or infinite */
57
	protected $depth;
58
	/** @var int - foreign key zu oc_account.id */
59
	protected $ownerAccountId;
60
61
	/** @var string - joined with oc_filecache */
62
	protected $path;
63
	/** @var string - computed value */
64
	protected $davUserId;
65
	/** @var string - computed value */
66
	protected $absoluteDavPath;
67
68
	public function __construct() {
69
		$this->addType('fileId', 'integer');
70
		$this->addType('timeout', 'integer');
71
		$this->addType('createdAt', 'integer');
72
		$this->addType('scope', 'integer');
73
		$this->addType('depth', 'integer');
74
		$this->addType('ownerAccountId', 'integer');
75
	}
76
77
	/**
78
	 * @param $token
79
	 */
80
	public function setToken($token) {
81
		parent::setter('token', [$token]);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setter() instead of setToken()). Are you sure this is correct? If so, you might want to change this to $this->setter().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
82
		parent::setter('tokenHash', [\md5($token)]);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setter() instead of setToken()). Are you sure this is correct? If so, you might want to change this to $this->setter().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
83
	}
84
85
	/**
86
	 * Return the owner of the lock - plain text field as transmitted by clients
87
	 *
88
	 * @return string
89
	 * @since 11.0.0
90
	 */
91
	public function getOwner(): ?string {
92
		return parent::getOwner();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class OCP\AppFramework\Db\Entity as the method getOwner() does only exist in the following sub-classes of OCP\AppFramework\Db\Entity: OC\Lock\Persistent\Lock, OC\Tagging\Tag. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
93
	}
94
95
	/**
96
	 * Foreign key to oc_filecache.fileid
97
	 *
98
	 * @return int
99
	 * @since 11.0.0
100
	 */
101
	public function getFileId(): int {
102
		return parent::getFileId();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class OCP\AppFramework\Db\Entity as the method getFileId() does only exist in the following sub-classes of OCP\AppFramework\Db\Entity: OC\Lock\Persistent\Lock. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
103
	}
104
105
	/**
106
	 * Seconds of lock life time
107
	 *
108
	 * @return int
109
	 * @since 11.0.0
110
	 */
111
	public function getTimeout(): int {
112
		return parent::getTimeout();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class OCP\AppFramework\Db\Entity as the method getTimeout() does only exist in the following sub-classes of OCP\AppFramework\Db\Entity: OC\Lock\Persistent\Lock. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
113
	}
114
115
	/**
116
	 * Unix timestamp when lock was created
117
	 *
118
	 * @return mixed
119
	 * @since 11.0.0
120
	 */
121
	public function getCreatedAt(): int {
122
		return parent::getCreatedAt();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class OCP\AppFramework\Db\Entity as the method getCreatedAt() does only exist in the following sub-classes of OCP\AppFramework\Db\Entity: OC\Lock\Persistent\Lock. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
123
	}
124
125
	/**
126
	 * Token to identify the lock - uuid usually
127
	 *
128
	 * @return string
129
	 * @since 11.0.0
130
	 */
131
	public function getToken(): string {
132
		return parent::getToken();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class OCP\AppFramework\Db\Entity as the method getToken() does only exist in the following sub-classes of OCP\AppFramework\Db\Entity: OC\Authentication\Token\DefaultToken, OC\Lock\Persistent\Lock. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
133
	}
134
135
	/**
136
	 * Either shared lock or exclusive lock
137
	 *
138
	 * @return int
139
	 * @since 11.0.0
140
	 */
141
	public function getScope(): int {
142
		return parent::getScope();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class OCP\AppFramework\Db\Entity as the method getScope() does only exist in the following sub-classes of OCP\AppFramework\Db\Entity: OC\Lock\Persistent\Lock. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
143
	}
144
145
	/**
146
	 * Depth as used in WebDAV: 0, 1 or infinite
147
	 *
148
	 * @return int
149
	 * @since 11.0.0
150
	 */
151
	public function getDepth(): int {
152
		return parent::getDepth();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class OCP\AppFramework\Db\Entity as the method getDepth() does only exist in the following sub-classes of OCP\AppFramework\Db\Entity: OC\Lock\Persistent\Lock. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
153
	}
154
155
	/**
156
	 * Absolute path to the file/folder on webdav
157
	 *
158
	 * @return string
159
	 * @since 11.0.0
160
	 */
161
	public function getAbsoluteDavPath(): string {
162
		return parent::getAbsoluteDavPath();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class OCP\AppFramework\Db\Entity as the method getAbsoluteDavPath() does only exist in the following sub-classes of OCP\AppFramework\Db\Entity: OC\Lock\Persistent\Lock. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
163
	}
164
165
	/**
166
	 * User id on webdav URI
167
	 *
168
	 * @return string
169
	 * @since 11.0.0
170
	 */
171
	public function getDavUserId(): string {
172
		return parent::getDavUserId();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class OCP\AppFramework\Db\Entity as the method getDavUserId() does only exist in the following sub-classes of OCP\AppFramework\Db\Entity: OC\Lock\Persistent\Lock. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
173
	}
174
175
	/**
176
	 * Set the owner
177
	 *
178
	 * @param string $owner
179
	 * @return mixed
180
	 * @since 11.0.0
181
	 */
182
	public function setOwner(?string $owner) : void {
183
		parent::setOwner($owner);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class OCP\AppFramework\Db\Entity as the method setOwner() does only exist in the following sub-classes of OCP\AppFramework\Db\Entity: OC\Lock\Persistent\Lock, OC\Tagging\Tag. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
184
	}
185
}
186