Fix inspection results
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
836271e0fd
commit
f0850b266e
|
@ -28,7 +28,7 @@ use Sabre\DAV\Exception\Forbidden;
|
|||
use Sabre\DAV\Exception\MethodNotAllowed;
|
||||
use Sabre\DAV\Exception\NotFound;
|
||||
use Sabre\DAV\ICollection;
|
||||
use Sabre\HTTP\URLUtil;
|
||||
use Sabre\Uri;
|
||||
|
||||
class AvatarHome implements ICollection {
|
||||
|
||||
|
@ -41,25 +41,26 @@ class AvatarHome implements ICollection {
|
|||
* AvatarHome constructor.
|
||||
*
|
||||
* @param array $principalInfo
|
||||
* @param IAvatarManager $avatarManager
|
||||
*/
|
||||
public function __construct($principalInfo, IAvatarManager $avatarManager) {
|
||||
$this->principalInfo = $principalInfo;
|
||||
$this->avatarManager = $avatarManager;
|
||||
}
|
||||
|
||||
function createFile($name, $data = null) {
|
||||
public function createFile($name, $data = null) {
|
||||
throw new Forbidden('Permission denied to create a file');
|
||||
}
|
||||
|
||||
function createDirectory($name) {
|
||||
public function createDirectory($name) {
|
||||
throw new Forbidden('Permission denied to create a folder');
|
||||
}
|
||||
|
||||
function getChild($name) {
|
||||
public function getChild($name) {
|
||||
$elements = pathinfo($name);
|
||||
$ext = isset($elements['extension']) ? $elements['extension'] : '';
|
||||
$size = intval(isset($elements['filename']) ? $elements['filename'] : '64');
|
||||
if (!in_array($ext, ['jpeg', 'png'])) {
|
||||
$size = (int)(isset($elements['filename']) ? $elements['filename'] : '64');
|
||||
if (!in_array($ext, ['jpeg', 'png'], true)) {
|
||||
throw new MethodNotAllowed('File format not allowed');
|
||||
}
|
||||
if ($size <= 0 || $size > 1024) {
|
||||
|
@ -72,7 +73,7 @@ class AvatarHome implements ICollection {
|
|||
return new AvatarNode($size, $ext, $avatar);
|
||||
}
|
||||
|
||||
function getChildren() {
|
||||
public function getChildren() {
|
||||
try {
|
||||
return [
|
||||
$this->getChild('96.jpeg')
|
||||
|
@ -82,10 +83,10 @@ class AvatarHome implements ICollection {
|
|||
}
|
||||
}
|
||||
|
||||
function childExists($name) {
|
||||
public function childExists($name) {
|
||||
try {
|
||||
$ret = $this->getChild($name);
|
||||
return !is_null($ret);
|
||||
return $ret !== null;
|
||||
} catch (NotFound $ex) {
|
||||
return false;
|
||||
} catch (MethodNotAllowed $ex) {
|
||||
|
@ -93,16 +94,16 @@ class AvatarHome implements ICollection {
|
|||
}
|
||||
}
|
||||
|
||||
function delete() {
|
||||
public function delete() {
|
||||
throw new Forbidden('Permission denied to delete this folder');
|
||||
}
|
||||
|
||||
function getName() {
|
||||
list(,$name) = URLUtil::splitPath($this->principalInfo['uri']);
|
||||
public function getName() {
|
||||
list(,$name) = Uri\split($this->principalInfo['uri']);
|
||||
return $name;
|
||||
}
|
||||
|
||||
function setName($name) {
|
||||
public function setName($name) {
|
||||
throw new Forbidden('Permission denied to rename this folder');
|
||||
}
|
||||
|
||||
|
@ -111,7 +112,7 @@ class AvatarHome implements ICollection {
|
|||
*
|
||||
* @return int
|
||||
*/
|
||||
function getLastModified() {
|
||||
public function getLastModified() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,11 +51,11 @@ class AvatarNode extends File {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
function getName() {
|
||||
public function getName() {
|
||||
return "$this->size.$this->ext";
|
||||
}
|
||||
|
||||
function get() {
|
||||
public function get() {
|
||||
$image = $this->avatar->get($this->size);
|
||||
$res = $image->resource();
|
||||
|
||||
|
@ -75,18 +75,18 @@ class AvatarNode extends File {
|
|||
*
|
||||
* @return string|null
|
||||
*/
|
||||
function getContentType() {
|
||||
public function getContentType() {
|
||||
if ($this->ext === 'png') {
|
||||
return 'image/png';
|
||||
}
|
||||
return 'image/jpeg';
|
||||
}
|
||||
|
||||
function getETag() {
|
||||
public function getETag() {
|
||||
return $this->avatar->getFile($this->size)->getEtag();
|
||||
}
|
||||
|
||||
function getLastModified() {
|
||||
public function getLastModified() {
|
||||
$timestamp = $this->avatar->getFile($this->size)->getMTime();
|
||||
if (!empty($timestamp)) {
|
||||
return (int)$timestamp;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace OCA\DAV\Avatars;
|
||||
|
||||
use Sabre\DAVACL\AbstractPrincipalCollection;
|
||||
use Sabre\DAVACL\IPrincipal;
|
||||
|
||||
|
||||
class RootCollection extends AbstractPrincipalCollection {
|
||||
|
||||
|
@ -17,12 +17,12 @@ class RootCollection extends AbstractPrincipalCollection {
|
|||
* @param array $principalInfo
|
||||
* @return AvatarHome
|
||||
*/
|
||||
function getChildForPrincipal(array $principalInfo) {
|
||||
public function getChildForPrincipal(array $principalInfo) {
|
||||
$avatarManager = \OC::$server->getAvatarManager();
|
||||
return new AvatarHome($principalInfo, $avatarManager);
|
||||
}
|
||||
|
||||
function getName() {
|
||||
public function getName() {
|
||||
return 'avatars';
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue