app/Integrations/Dav/Backend/Auth.php
The method challenge uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
Open
} else {
parent::challenge($request, $response);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Parameter $request
has undeclared type \Sabre\HTTP\RequestInterface
Open
Open
public function challenge(RequestInterface $request, ResponseInterface $response)
- Exclude checks
Reference to undeclared property \App\Integrations\Dav\Backend\Auth->principalPrefix
Open
Open
return [true, $this->principalPrefix . $userpass[0]];
- Exclude checks
Parameter $request
has undeclared type \Sabre\HTTP\RequestInterface
Open
Open
public function checkBasic(RequestInterface $request, ResponseInterface $response)
- Exclude checks
Call to method __construct
from undeclared class \Sabre\HTTP\auth\basic
Open
Open
$auth = new HTTP\Auth\Basic(
- Exclude checks
Call to undeclared method \App\Integrations\Dav\Backend\Auth::getDigestHash
Open
Open
$hash = $this->getDigestHash($this->realm, $userpass[0]);
- Exclude checks
Class extends undeclared class \Sabre\DAV\auth\backend\pdo
(Did you mean class \PDO) Open
Open
class Auth extends DAV\Auth\Backend\PDO
- Exclude checks
Reference to undeclared class \Sabre\DAV\auth\backend\pdo
(Did you mean class \PDO) Open
Open
return parent::check($request, $response);
- Exclude checks
Parameter $response
has undeclared type \Sabre\HTTP\ResponseInterface
Open
Open
public function checkBasic(RequestInterface $request, ResponseInterface $response)
- Exclude checks
Parameter $request
has undeclared type \Sabre\HTTP\RequestInterface
Open
Open
public function check(RequestInterface $request, ResponseInterface $response)
- Exclude checks
Call to method getHeader
from undeclared class \Sabre\HTTP\RequestInterface
Open
Open
if (0 === strpos($request->getHeader('Authorization'), 'Basic')) {
- Exclude checks
Parameter $response
has undeclared type \Sabre\HTTP\ResponseInterface
Open
Open
public function check(RequestInterface $request, ResponseInterface $response)
- Exclude checks
Parameter $response
has undeclared type \Sabre\HTTP\ResponseInterface
Open
Open
public function challenge(RequestInterface $request, ResponseInterface $response)
- Exclude checks
Call to method getHeader
from undeclared class \Sabre\HTTP\RequestInterface
Open
Open
if (0 === strpos($request->getHeader('Authorization'), 'Basic')) {
- Exclude checks
Call to method getCredentials
from undeclared class \Sabre\HTTP\auth\basic
Open
Open
$userpass = $auth->getCredentials();
- Exclude checks
Reference to undeclared class \Sabre\DAV\auth\backend\pdo
(Did you mean class \PDO) Open
Open
parent::challenge($request, $response);
- Exclude checks
Call to method requireLogin
from undeclared class \Sabre\HTTP\auth\basic
Open
Open
$auth->requireLogin();
- Exclude checks
Call to method __construct
from undeclared class \Sabre\HTTP\auth\basic
Open
Open
$auth = new HTTP\Auth\Basic(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Keep in mind that in the case of multiple authentication backends, other
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function challenge(RequestInterface $request, ResponseInterface $response)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$request,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public $tableName = 'dav_users';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* principals/admin
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* backend returns a so-called principal url.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
parent::challenge($request, $response);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* When this method is called, the backend must check if authentication was
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return parent::check($request, $response);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param RequestInterface $request
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param ResponseInterface $response
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @var string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* principals/users/[username]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function check(RequestInterface $request, ResponseInterface $response)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* If authentication was successful, it's expected that the authentication
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return [false, 'Username or password was incorrect'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* PDO table name we'll be using.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @var string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* principals/admin
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* principals/user1
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return [false, "No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured"];
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
Open
return [false, "No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured"];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* WWW-Authenticate headers may already have been set, and you'll want to
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* principals/user1
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* principals/uid/123457
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* return a string such as:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param ResponseInterface $response
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$response
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* authentication was required for the current request.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* [false, "reason for failure"]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* return a string such as:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* The returned value must be one of the following
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return [true, $this->principalPrefix . $userpass[0]];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* existing one.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$auth->requireLogin();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* The realm is often displayed by browser clients when showing the
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* If you don't use WebDAV ACL (RFC3744) we recommend that you simply
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* [true, "principals/username"]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public function checkBasic(RequestInterface $request, ResponseInterface $response)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$userpass = $auth->getCredentials();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (!$userpass) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* authentication dialog.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
protected $realm = 'YetiDAV';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* The returned value must be one of the following
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Examples of a principal url:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* principals/users/joe
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return $this->checkBasic($request, $response);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* If you don't use WebDAV ACL (RFC3744) we recommend that you simply
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* principals/users/[username]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* When this method is called, the backend must check if authentication was
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* principals/users/joe
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$request,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (md5($userpass[0] . ':' . $this->realm . ':' . $userpass[1]) !== $hash) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* This method is called when a user could not be authenticated, and
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* In this case of Basic Auth, this would for example mean that the
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Authentication Realm.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Examples of a principal url:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* If authentication was successful, it's expected that the authentication
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* principals/uid/123457
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$hash = $this->getDigestHash($this->realm, $userpass[0]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param RequestInterface $request
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* [false, "reason for failure"]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* following header needs to be set:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* append your own WWW-Authenticate header instead of overwriting the
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$auth = new HTTP\Auth\Basic(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* status code will already be set.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->realm,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (0 === strpos($request->getHeader('Authorization'), 'Basic')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$this->realm,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* successful.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param RequestInterface $request
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$auth = new HTTP\Auth\Basic(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* This gives you the opportunity to set authentication headers. The 401
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$response
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* [true, "principals/username"]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (0 === strpos($request->getHeader('Authorization'), 'Basic')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* successful.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* backend returns a so-called principal url.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param ResponseInterface $response
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks