Passed
Push — master ( 645109...008e6d )
by Christoph
12:14 queued 12s
created
lib/public/Search/Result.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -31,47 +31,47 @@
 block discarded – undo
31 31
  */
32 32
 class Result {
33 33
 
34
-	/**
35
-	 * A unique identifier for the result, usually given as the item ID in its
36
-	 * corresponding application.
37
-	 * @var string
38
-	 * @since 7.0.0
39
-	 */
40
-	public $id;
34
+    /**
35
+     * A unique identifier for the result, usually given as the item ID in its
36
+     * corresponding application.
37
+     * @var string
38
+     * @since 7.0.0
39
+     */
40
+    public $id;
41 41
 
42
-	/**
43
-	 * The name of the item returned; this will be displayed in the search
44
-	 * results.
45
-	 * @var string
46
-	 * @since 7.0.0
47
-	 */
48
-	public $name;
42
+    /**
43
+     * The name of the item returned; this will be displayed in the search
44
+     * results.
45
+     * @var string
46
+     * @since 7.0.0
47
+     */
48
+    public $name;
49 49
 
50
-	/**
51
-	 * URL to the application item.
52
-	 * @var string
53
-	 * @since 7.0.0
54
-	 */
55
-	public $link;
50
+    /**
51
+     * URL to the application item.
52
+     * @var string
53
+     * @since 7.0.0
54
+     */
55
+    public $link;
56 56
 
57
-	/**
58
-	 * The type of search result returned; for consistency, name this the same
59
-	 * as the class name (e.g. \OC\Search\File -> 'file') in lowercase.
60
-	 * @var string
61
-	 * @since 7.0.0
62
-	 */
63
-	public $type = 'generic';
57
+    /**
58
+     * The type of search result returned; for consistency, name this the same
59
+     * as the class name (e.g. \OC\Search\File -> 'file') in lowercase.
60
+     * @var string
61
+     * @since 7.0.0
62
+     */
63
+    public $type = 'generic';
64 64
 
65
-	/**
66
-	 * Create a new search result
67
-	 * @param string $id unique identifier from application: '[app_name]/[item_identifier_in_app]'
68
-	 * @param string $name displayed text of result
69
-	 * @param string $link URL to the result within its app
70
-	 * @since 7.0.0
71
-	 */
72
-	public function __construct($id = null, $name = null, $link = null) {
73
-		$this->id = $id;
74
-		$this->name = $name;
75
-		$this->link = $link;
76
-	}
65
+    /**
66
+     * Create a new search result
67
+     * @param string $id unique identifier from application: '[app_name]/[item_identifier_in_app]'
68
+     * @param string $name displayed text of result
69
+     * @param string $link URL to the result within its app
70
+     * @since 7.0.0
71
+     */
72
+    public function __construct($id = null, $name = null, $link = null) {
73
+        $this->id = $id;
74
+        $this->name = $name;
75
+        $this->link = $link;
76
+    }
77 77
 }
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/HomeObjectStoreStorage.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -28,40 +28,40 @@
 block discarded – undo
28 28
 
29 29
 class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage {
30 30
 
31
-	/**
32
-	 * The home user storage requires a user object to create a unique storage id
33
-	 * @param array $params
34
-	 */
35
-	public function __construct($params) {
36
-		if (! isset($params['user']) || ! $params['user'] instanceof User) {
37
-			throw new \Exception('missing user object in parameters');
38
-		}
39
-		$this->user = $params['user'];
40
-		parent::__construct($params);
41
-	}
31
+    /**
32
+     * The home user storage requires a user object to create a unique storage id
33
+     * @param array $params
34
+     */
35
+    public function __construct($params) {
36
+        if (! isset($params['user']) || ! $params['user'] instanceof User) {
37
+            throw new \Exception('missing user object in parameters');
38
+        }
39
+        $this->user = $params['user'];
40
+        parent::__construct($params);
41
+    }
42 42
 
43
-	public function getId() {
44
-		return 'object::user:' . $this->user->getUID();
45
-	}
43
+    public function getId() {
44
+        return 'object::user:' . $this->user->getUID();
45
+    }
46 46
 
47
-	/**
48
-	 * get the owner of a path
49
-	 *
50
-	 * @param string $path The path to get the owner
51
-	 * @return false|string uid
52
-	 */
53
-	public function getOwner($path) {
54
-		if (is_object($this->user)) {
55
-			return $this->user->getUID();
56
-		}
57
-		return false;
58
-	}
47
+    /**
48
+     * get the owner of a path
49
+     *
50
+     * @param string $path The path to get the owner
51
+     * @return false|string uid
52
+     */
53
+    public function getOwner($path) {
54
+        if (is_object($this->user)) {
55
+            return $this->user->getUID();
56
+        }
57
+        return false;
58
+    }
59 59
 
60
-	/**
61
-	 * @param string $path, optional
62
-	 * @return \OC\User\User
63
-	 */
64
-	public function getUser($path = null) {
65
-		return $this->user;
66
-	}
60
+    /**
61
+     * @param string $path, optional
62
+     * @return \OC\User\User
63
+     */
64
+    public function getUser($path = null) {
65
+        return $this->user;
66
+    }
67 67
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 * @param array $params
34 34
 	 */
35 35
 	public function __construct($params) {
36
-		if (! isset($params['user']) || ! $params['user'] instanceof User) {
36
+		if (!isset($params['user']) || !$params['user'] instanceof User) {
37 37
 			throw new \Exception('missing user object in parameters');
38 38
 		}
39 39
 		$this->user = $params['user'];
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	}
42 42
 
43 43
 	public function getId() {
44
-		return 'object::user:' . $this->user->getUID();
44
+		return 'object::user:'.$this->user->getUID();
45 45
 	}
46 46
 
47 47
 	/**
Please login to merge, or discard this patch.
lib/private/Search/Result/Audio.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,13 +29,13 @@
 block discarded – undo
29 29
  */
30 30
 class Audio extends File {
31 31
 
32
-	/**
33
-	 * Type name; translated in templates
34
-	 * @var string
35
-	 */
36
-	public $type = 'audio';
32
+    /**
33
+     * Type name; translated in templates
34
+     * @var string
35
+     */
36
+    public $type = 'audio';
37 37
 	
38
-	/**
39
-	 * @TODO add ID3 information
40
-	 */
38
+    /**
39
+     * @TODO add ID3 information
40
+     */
41 41
 }
Please login to merge, or discard this patch.
lib/private/Search/Result/Image.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,13 +29,13 @@
 block discarded – undo
29 29
  */
30 30
 class Image extends File {
31 31
 
32
-	/**
33
-	 * Type name; translated in templates
34
-	 * @var string
35
-	 */
36
-	public $type = 'image';
32
+    /**
33
+     * Type name; translated in templates
34
+     * @var string
35
+     */
36
+    public $type = 'image';
37 37
 	
38
-	/**
39
-	 * @TODO add EXIF information
40
-	 */
38
+    /**
39
+     * @TODO add EXIF information
40
+     */
41 41
 }
Please login to merge, or discard this patch.
lib/private/Search/Result/Folder.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,9 +29,9 @@
 block discarded – undo
29 29
  */
30 30
 class Folder extends File {
31 31
 
32
-	/**
33
-	 * Type name; translated in templates
34
-	 * @var string
35
-	 */
36
-	public $type = 'folder';
32
+    /**
33
+     * Type name; translated in templates
34
+     * @var string
35
+     */
36
+    public $type = 'folder';
37 37
 }
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/ImageExportPlugin.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@
 block discarded – undo
71 71
 			return true;
72 72
 		}
73 73
 
74
-		$size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1;
74
+		$size = isset($queryParams['size']) ? (int) $queryParams['size'] : -1;
75 75
 
76 76
 		$path = $request->getPath();
77 77
 		$node = $this->server->tree->getNodeForPath($path);
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -32,85 +32,85 @@
 block discarded – undo
32 32
 
33 33
 class ImageExportPlugin extends ServerPlugin {
34 34
 
35
-	/** @var Server */
36
-	protected $server;
37
-	/** @var PhotoCache */
38
-	private $cache;
39
-
40
-	/**
41
-	 * ImageExportPlugin constructor.
42
-	 *
43
-	 * @param PhotoCache $cache
44
-	 */
45
-	public function __construct(PhotoCache $cache) {
46
-		$this->cache = $cache;
47
-	}
48
-
49
-	/**
50
-	 * Initializes the plugin and registers event handlers
51
-	 *
52
-	 * @param Server $server
53
-	 * @return void
54
-	 */
55
-	public function initialize(Server $server) {
56
-		$this->server = $server;
57
-		$this->server->on('method:GET', [$this, 'httpGet'], 90);
58
-	}
59
-
60
-	/**
61
-	 * Intercepts GET requests on addressbook urls ending with ?photo.
62
-	 *
63
-	 * @param RequestInterface $request
64
-	 * @param ResponseInterface $response
65
-	 * @return bool
66
-	 */
67
-	public function httpGet(RequestInterface $request, ResponseInterface $response) {
68
-
69
-		$queryParams = $request->getQueryParameters();
70
-		// TODO: in addition to photo we should also add logo some point in time
71
-		if (!array_key_exists('photo', $queryParams)) {
72
-			return true;
73
-		}
74
-
75
-		$size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1;
76
-
77
-		$path = $request->getPath();
78
-		$node = $this->server->tree->getNodeForPath($path);
79
-
80
-		if (!($node instanceof Card)) {
81
-			return true;
82
-		}
83
-
84
-		$this->server->transactionType = 'carddav-image-export';
85
-
86
-		// Checking ACL, if available.
87
-		if ($aclPlugin = $this->server->getPlugin('acl')) {
88
-			/** @var \Sabre\DAVACL\Plugin $aclPlugin */
89
-			$aclPlugin->checkPrivileges($path, '{DAV:}read');
90
-		}
91
-
92
-		// Fetch addressbook
93
-		$addressbookpath = explode('/', $path);
94
-		array_pop($addressbookpath);
95
-		$addressbookpath = implode('/', $addressbookpath);
96
-		/** @var AddressBook $addressbook */
97
-		$addressbook = $this->server->tree->getNodeForPath($addressbookpath);
98
-
99
-		$response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate');
100
-		$response->setHeader('Etag', $node->getETag());
101
-		$response->setHeader('Pragma', 'public');
102
-
103
-		try {
104
-			$file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node);
105
-			$response->setHeader('Content-Type', $file->getMimeType());
106
-			$response->setHeader('Content-Disposition', 'attachment');
107
-			$response->setStatus(200);
108
-
109
-			$response->setBody($file->getContent());
110
-		} catch (NotFoundException $e) {
111
-			$response->setStatus(404);
112
-		}
113
-
114
-		return false;
115
-	}
35
+    /** @var Server */
36
+    protected $server;
37
+    /** @var PhotoCache */
38
+    private $cache;
39
+
40
+    /**
41
+     * ImageExportPlugin constructor.
42
+     *
43
+     * @param PhotoCache $cache
44
+     */
45
+    public function __construct(PhotoCache $cache) {
46
+        $this->cache = $cache;
47
+    }
48
+
49
+    /**
50
+     * Initializes the plugin and registers event handlers
51
+     *
52
+     * @param Server $server
53
+     * @return void
54
+     */
55
+    public function initialize(Server $server) {
56
+        $this->server = $server;
57
+        $this->server->on('method:GET', [$this, 'httpGet'], 90);
58
+    }
59
+
60
+    /**
61
+     * Intercepts GET requests on addressbook urls ending with ?photo.
62
+     *
63
+     * @param RequestInterface $request
64
+     * @param ResponseInterface $response
65
+     * @return bool
66
+     */
67
+    public function httpGet(RequestInterface $request, ResponseInterface $response) {
68
+
69
+        $queryParams = $request->getQueryParameters();
70
+        // TODO: in addition to photo we should also add logo some point in time
71
+        if (!array_key_exists('photo', $queryParams)) {
72
+            return true;
73
+        }
74
+
75
+        $size = isset($queryParams['size']) ? (int)$queryParams['size'] : -1;
76
+
77
+        $path = $request->getPath();
78
+        $node = $this->server->tree->getNodeForPath($path);
79
+
80
+        if (!($node instanceof Card)) {
81
+            return true;
82
+        }
83
+
84
+        $this->server->transactionType = 'carddav-image-export';
85
+
86
+        // Checking ACL, if available.
87
+        if ($aclPlugin = $this->server->getPlugin('acl')) {
88
+            /** @var \Sabre\DAVACL\Plugin $aclPlugin */
89
+            $aclPlugin->checkPrivileges($path, '{DAV:}read');
90
+        }
91
+
92
+        // Fetch addressbook
93
+        $addressbookpath = explode('/', $path);
94
+        array_pop($addressbookpath);
95
+        $addressbookpath = implode('/', $addressbookpath);
96
+        /** @var AddressBook $addressbook */
97
+        $addressbook = $this->server->tree->getNodeForPath($addressbookpath);
98
+
99
+        $response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate');
100
+        $response->setHeader('Etag', $node->getETag());
101
+        $response->setHeader('Pragma', 'public');
102
+
103
+        try {
104
+            $file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node);
105
+            $response->setHeader('Content-Type', $file->getMimeType());
106
+            $response->setHeader('Content-Disposition', 'attachment');
107
+            $response->setStatus(200);
108
+
109
+            $response->setBody($file->getContent());
110
+        } catch (NotFoundException $e) {
111
+            $response->setStatus(404);
112
+        }
113
+
114
+        return false;
115
+    }
116 116
 }
Please login to merge, or discard this patch.
apps/encryption/templates/altmail.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 print_unescaped($l->t("Hey there,\n\nthe admin enabled server-side-encryption. Your files were encrypted using the password '%s'.\n\nPlease login to the web interface, go to the section 'basic encryption module' of your personal settings and update your encryption password by entering this password into the 'old log-in password' field and your current login-password.\n\n", [$_['password']]));
6 6
 if (isset($_['expiration'])) {
7
-	print_unescaped($l->t("The share will expire on %s.", [$_['expiration']]));
8
-	print_unescaped("\n\n");
7
+    print_unescaped($l->t("The share will expire on %s.", [$_['expiration']]));
8
+    print_unescaped("\n\n");
9 9
 }
10 10
 // TRANSLATORS term at the end of a mail
11 11
 p($l->t("Cheers!"));
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,5 +6,5 @@
 block discarded – undo
6 6
 ?>
7 7
 
8 8
 	--
9
-<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?>
9
+<?php p($theme->getName().' - '.$theme->getSlogan()); ?>
10 10
 <?php print_unescaped("\n".$theme->getBaseUrl());
Please login to merge, or discard this patch.
lib/public/Files.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -48,73 +48,73 @@
 block discarded – undo
48 48
  * @deprecated 14.0.0
49 49
  */
50 50
 class Files {
51
-	/**
52
-	 * Recusive deletion of folders
53
-	 * @return bool
54
-	 * @since 5.0.0
55
-	 * @deprecated 14.0.0
56
-	 */
57
-	static public function rmdirr($dir) {
58
-		return \OC_Helper::rmdirr($dir);
59
-	}
51
+    /**
52
+     * Recusive deletion of folders
53
+     * @return bool
54
+     * @since 5.0.0
55
+     * @deprecated 14.0.0
56
+     */
57
+    static public function rmdirr($dir) {
58
+        return \OC_Helper::rmdirr($dir);
59
+    }
60 60
 
61
-	/**
62
-	 * Get the mimetype form a local file
63
-	 * @param string $path
64
-	 * @return string
65
-	 * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
66
-	 * @since 5.0.0
67
-	 * @deprecated 14.0.0
68
-	 */
69
-	static public function getMimeType($path) {
70
-		return \OC::$server->getMimeTypeDetector()->detect($path);
71
-	}
61
+    /**
62
+     * Get the mimetype form a local file
63
+     * @param string $path
64
+     * @return string
65
+     * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
66
+     * @since 5.0.0
67
+     * @deprecated 14.0.0
68
+     */
69
+    static public function getMimeType($path) {
70
+        return \OC::$server->getMimeTypeDetector()->detect($path);
71
+    }
72 72
 
73
-	/**
74
-	 * Search for files by mimetype
75
-	 * @param string $mimetype
76
-	 * @return array
77
-	 * @since 6.0.0
78
-	 * @deprecated 14.0.0
79
-	 */
80
-	static public function searchByMime($mimetype) {
81
-		return \OC\Files\Filesystem::searchByMime($mimetype);
82
-	}
73
+    /**
74
+     * Search for files by mimetype
75
+     * @param string $mimetype
76
+     * @return array
77
+     * @since 6.0.0
78
+     * @deprecated 14.0.0
79
+     */
80
+    static public function searchByMime($mimetype) {
81
+        return \OC\Files\Filesystem::searchByMime($mimetype);
82
+    }
83 83
 
84
-	/**
85
-	 * Copy the contents of one stream to another
86
-	 * @param resource $source
87
-	 * @param resource $target
88
-	 * @return int the number of bytes copied
89
-	 * @since 5.0.0
90
-	 * @deprecated 14.0.0
91
-	 */
92
-	public static function streamCopy($source, $target) {
93
-		list($count, ) = \OC_Helper::streamCopy($source, $target);
94
-		return $count;
95
-	}
84
+    /**
85
+     * Copy the contents of one stream to another
86
+     * @param resource $source
87
+     * @param resource $target
88
+     * @return int the number of bytes copied
89
+     * @since 5.0.0
90
+     * @deprecated 14.0.0
91
+     */
92
+    public static function streamCopy($source, $target) {
93
+        list($count, ) = \OC_Helper::streamCopy($source, $target);
94
+        return $count;
95
+    }
96 96
 
97
-	/**
98
-	 * Adds a suffix to the name in case the file exists
99
-	 * @param string $path
100
-	 * @param string $filename
101
-	 * @return string
102
-	 * @since 5.0.0
103
-	 * @deprecated 14.0.0 use getNonExistingName of the OCP\Files\Folder object
104
-	 */
105
-	public static function buildNotExistingFileName($path, $filename) {
106
-		return \OC_Helper::buildNotExistingFileName($path, $filename);
107
-	}
97
+    /**
98
+     * Adds a suffix to the name in case the file exists
99
+     * @param string $path
100
+     * @param string $filename
101
+     * @return string
102
+     * @since 5.0.0
103
+     * @deprecated 14.0.0 use getNonExistingName of the OCP\Files\Folder object
104
+     */
105
+    public static function buildNotExistingFileName($path, $filename) {
106
+        return \OC_Helper::buildNotExistingFileName($path, $filename);
107
+    }
108 108
 
109
-	/**
110
-	 * Gets the Storage for an app - creates the needed folder if they are not
111
-	 * existent
112
-	 * @param string $app
113
-	 * @return \OC\Files\View
114
-	 * @since 5.0.0
115
-	 * @deprecated 14.0.0 use IAppData instead
116
-	 */
117
-	public static function getStorage($app) {
118
-		return \OC_App::getStorage($app);
119
-	}
109
+    /**
110
+     * Gets the Storage for an app - creates the needed folder if they are not
111
+     * existent
112
+     * @param string $app
113
+     * @return \OC\Files\View
114
+     * @since 5.0.0
115
+     * @deprecated 14.0.0 use IAppData instead
116
+     */
117
+    public static function getStorage($app) {
118
+        return \OC_App::getStorage($app);
119
+    }
120 120
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@
 block discarded – undo
90 90
 	 * @deprecated 14.0.0
91 91
 	 */
92 92
 	public static function streamCopy($source, $target) {
93
-		list($count, ) = \OC_Helper::streamCopy($source, $target);
93
+		list($count,) = \OC_Helper::streamCopy($source, $target);
94 94
 		return $count;
95 95
 	}
96 96
 
Please login to merge, or discard this patch.
lib/public/AppFramework/Db/QBMapper.php 2 patches
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -42,294 +42,294 @@
 block discarded – undo
42 42
  */
43 43
 abstract class QBMapper {
44 44
 
45
-	/** @var string */
46
-	protected $tableName;
47
-
48
-	/** @var string */
49
-	protected $entityClass;
50
-
51
-	/** @var IDBConnection */
52
-	protected $db;
53
-
54
-	/**
55
-	 * @param IDBConnection $db Instance of the Db abstraction layer
56
-	 * @param string $tableName the name of the table. set this to allow entity
57
-	 * @param string $entityClass the name of the entity that the sql should be
58
-	 * mapped to queries without using sql
59
-	 * @since 14.0.0
60
-	 */
61
-	public function __construct(IDBConnection $db, string $tableName, string $entityClass=null) {
62
-		$this->db = $db;
63
-		$this->tableName = $tableName;
64
-
65
-		// if not given set the entity name to the class without the mapper part
66
-		// cache it here for later use since reflection is slow
67
-		if($entityClass === null) {
68
-			$this->entityClass = str_replace('Mapper', '', \get_class($this));
69
-		} else {
70
-			$this->entityClass = $entityClass;
71
-		}
72
-	}
73
-
74
-
75
-	/**
76
-	 * @return string the table name
77
-	 * @since 14.0.0
78
-	 */
79
-	public function getTableName(): string {
80
-		return $this->tableName;
81
-	}
82
-
83
-
84
-	/**
85
-	 * Deletes an entity from the table
86
-	 * @param Entity $entity the entity that should be deleted
87
-	 * @return Entity the deleted entity
88
-	 * @since 14.0.0
89
-	 */
90
-	public function delete(Entity $entity): Entity {
91
-		$qb = $this->db->getQueryBuilder();
92
-
93
-		$idType = $this->getParameterTypeForProperty($entity, 'id');
94
-
95
-		$qb->delete($this->tableName)
96
-			->where(
97
-				$qb->expr()->eq('id', $qb->createNamedParameter($entity->getId(), $idType))
98
-			);
99
-		$qb->execute();
100
-		return $entity;
101
-	}
102
-
103
-
104
-	/**
105
-	 * Creates a new entry in the db from an entity
106
-	 * @param Entity $entity the entity that should be created
107
-	 * @return Entity the saved entity with the set id
108
-	 * @since 14.0.0
109
-	 * @suppress SqlInjectionChecker
110
-	 */
111
-	public function insert(Entity $entity): Entity {
112
-		// get updated fields to save, fields have to be set using a setter to
113
-		// be saved
114
-		$properties = $entity->getUpdatedFields();
115
-
116
-		$qb = $this->db->getQueryBuilder();
117
-		$qb->insert($this->tableName);
118
-
119
-		// build the fields
120
-		foreach($properties as $property => $updated) {
121
-			$column = $entity->propertyToColumn($property);
122
-			$getter = 'get' . ucfirst($property);
123
-			$value = $entity->$getter();
124
-
125
-			$type = $this->getParameterTypeForProperty($entity, $property);
126
-			$qb->setValue($column, $qb->createNamedParameter($value, $type));
127
-		}
128
-
129
-		$qb->execute();
130
-
131
-		if($entity->id === null) {
132
-			// When autoincrement is used id is always an int
133
-			$entity->setId((int)$qb->getLastInsertId());
134
-		}
135
-
136
-		return $entity;
137
-	}
138
-
139
-	/**
140
-	 * Tries to creates a new entry in the db from an entity and
141
-	 * updates an existing entry if duplicate keys are detected
142
-	 * by the database
143
-	 *
144
-	 * @param Entity $entity the entity that should be created/updated
145
-	 * @return Entity the saved entity with the (new) id
146
-	 * @throws \InvalidArgumentException if entity has no id
147
-	 * @since 15.0.0
148
-	 * @suppress SqlInjectionChecker
149
-	 */
150
-	public function insertOrUpdate(Entity $entity): Entity {
151
-		try {
152
-			return $this->insert($entity);
153
-		} catch (UniqueConstraintViolationException $ex) {
154
-			return $this->update($entity);
155
-		}
156
-	}
157
-
158
-	/**
159
-	 * Updates an entry in the db from an entity
160
-	 * @throws \InvalidArgumentException if entity has no id
161
-	 * @param Entity $entity the entity that should be created
162
-	 * @return Entity the saved entity with the set id
163
-	 * @since 14.0.0
164
-	 * @suppress SqlInjectionChecker
165
-	 */
166
-	public function update(Entity $entity): Entity {
167
-		// if entity wasn't changed it makes no sense to run a db query
168
-		$properties = $entity->getUpdatedFields();
169
-		if(\count($properties) === 0) {
170
-			return $entity;
171
-		}
172
-
173
-		// entity needs an id
174
-		$id = $entity->getId();
175
-		if($id === null){
176
-			throw new \InvalidArgumentException(
177
-				'Entity which should be updated has no id');
178
-		}
179
-
180
-		// get updated fields to save, fields have to be set using a setter to
181
-		// be saved
182
-		// do not update the id field
183
-		unset($properties['id']);
184
-
185
-		$qb = $this->db->getQueryBuilder();
186
-		$qb->update($this->tableName);
187
-
188
-		// build the fields
189
-		foreach($properties as $property => $updated) {
190
-			$column = $entity->propertyToColumn($property);
191
-			$getter = 'get' . ucfirst($property);
192
-			$value = $entity->$getter();
193
-
194
-			$type = $this->getParameterTypeForProperty($entity, $property);
195
-			$qb->set($column, $qb->createNamedParameter($value, $type));
196
-		}
197
-
198
-		$idType = $this->getParameterTypeForProperty($entity, 'id');
199
-
200
-		$qb->where(
201
-			$qb->expr()->eq('id', $qb->createNamedParameter($id, $idType))
202
-		);
203
-		$qb->execute();
204
-
205
-		return $entity;
206
-	}
207
-
208
-	/**
209
-	 * Returns the type parameter for the QueryBuilder for a specific property
210
-	 * of the $entity
211
-	 *
212
-	 * @param Entity $entity   The entity to get the types from
213
-	 * @param string $property The property of $entity to get the type for
214
-	 * @return int
215
-	 * @since 16.0.0
216
-	 */
217
-	protected function getParameterTypeForProperty(Entity $entity, string $property): int {
218
-		$types = $entity->getFieldTypes();
219
-
220
-		if(!isset($types[ $property ])) {
221
-			return IQueryBuilder::PARAM_STR;
222
-		}
223
-
224
-		switch($types[ $property ]) {
225
-			case 'int':
226
-			case 'integer':
227
-				return IQueryBuilder::PARAM_INT;
228
-			case 'string':
229
-				return IQueryBuilder::PARAM_STR;
230
-			case 'bool':
231
-			case 'boolean':
232
-				return IQueryBuilder::PARAM_BOOL;
233
-		}
234
-
235
-		return IQueryBuilder::PARAM_STR;
236
-	}
237
-
238
-	/**
239
-	 * Returns an db result and throws exceptions when there are more or less
240
-	 * results
241
-	 *
242
-	 * @see findEntity
243
-	 *
244
-	 * @param IQueryBuilder $query
245
-	 * @throws DoesNotExistException if the item does not exist
246
-	 * @throws MultipleObjectsReturnedException if more than one item exist
247
-	 * @return array the result as row
248
-	 * @since 14.0.0
249
-	 */
250
-	protected function findOneQuery(IQueryBuilder $query): array {
251
-		$cursor = $query->execute();
252
-
253
-		$row = $cursor->fetch();
254
-		if($row === false) {
255
-			$cursor->closeCursor();
256
-			$msg = $this->buildDebugMessage(
257
-				'Did expect one result but found none when executing', $query
258
-			);
259
-			throw new DoesNotExistException($msg);
260
-		}
261
-
262
-		$row2 = $cursor->fetch();
263
-		$cursor->closeCursor();
264
-		if($row2 !== false) {
265
-			$msg = $this->buildDebugMessage(
266
-				'Did not expect more than one result when executing', $query
267
-			);
268
-			throw new MultipleObjectsReturnedException($msg);
269
-		}
270
-
271
-		return $row;
272
-	}
273
-
274
-	/**
275
-	 * @param string $msg
276
-	 * @param IQueryBuilder $sql
277
-	 * @return string
278
-	 * @since 14.0.0
279
-	 */
280
-	private function buildDebugMessage(string $msg, IQueryBuilder $sql): string {
281
-		return $msg .
282
-			': query "' . $sql->getSQL() . '"; ';
283
-	}
284
-
285
-
286
-	/**
287
-	 * Creates an entity from a row. Automatically determines the entity class
288
-	 * from the current mapper name (MyEntityMapper -> MyEntity)
289
-	 *
290
-	 * @param array $row the row which should be converted to an entity
291
-	 * @return Entity the entity
292
-	 * @since 14.0.0
293
-	 */
294
-	protected function mapRowToEntity(array $row): Entity {
295
-		return \call_user_func($this->entityClass .'::fromRow', $row);
296
-	}
297
-
298
-
299
-	/**
300
-	 * Runs a sql query and returns an array of entities
301
-	 *
302
-	 * @param IQueryBuilder $query
303
-	 * @return Entity[] all fetched entities
304
-	 * @since 14.0.0
305
-	 */
306
-	protected function findEntities(IQueryBuilder $query): array {
307
-		$cursor = $query->execute();
308
-
309
-		$entities = [];
310
-
311
-		while($row = $cursor->fetch()){
312
-			$entities[] = $this->mapRowToEntity($row);
313
-		}
314
-
315
-		$cursor->closeCursor();
316
-
317
-		return $entities;
318
-	}
319
-
320
-
321
-	/**
322
-	 * Returns an db result and throws exceptions when there are more or less
323
-	 * results
324
-	 *
325
-	 * @param IQueryBuilder $query
326
-	 * @throws DoesNotExistException if the item does not exist
327
-	 * @throws MultipleObjectsReturnedException if more than one item exist
328
-	 * @return Entity the entity
329
-	 * @since 14.0.0
330
-	 */
331
-	protected function findEntity(IQueryBuilder $query): Entity {
332
-		return $this->mapRowToEntity($this->findOneQuery($query));
333
-	}
45
+    /** @var string */
46
+    protected $tableName;
47
+
48
+    /** @var string */
49
+    protected $entityClass;
50
+
51
+    /** @var IDBConnection */
52
+    protected $db;
53
+
54
+    /**
55
+     * @param IDBConnection $db Instance of the Db abstraction layer
56
+     * @param string $tableName the name of the table. set this to allow entity
57
+     * @param string $entityClass the name of the entity that the sql should be
58
+     * mapped to queries without using sql
59
+     * @since 14.0.0
60
+     */
61
+    public function __construct(IDBConnection $db, string $tableName, string $entityClass=null) {
62
+        $this->db = $db;
63
+        $this->tableName = $tableName;
64
+
65
+        // if not given set the entity name to the class without the mapper part
66
+        // cache it here for later use since reflection is slow
67
+        if($entityClass === null) {
68
+            $this->entityClass = str_replace('Mapper', '', \get_class($this));
69
+        } else {
70
+            $this->entityClass = $entityClass;
71
+        }
72
+    }
73
+
74
+
75
+    /**
76
+     * @return string the table name
77
+     * @since 14.0.0
78
+     */
79
+    public function getTableName(): string {
80
+        return $this->tableName;
81
+    }
82
+
83
+
84
+    /**
85
+     * Deletes an entity from the table
86
+     * @param Entity $entity the entity that should be deleted
87
+     * @return Entity the deleted entity
88
+     * @since 14.0.0
89
+     */
90
+    public function delete(Entity $entity): Entity {
91
+        $qb = $this->db->getQueryBuilder();
92
+
93
+        $idType = $this->getParameterTypeForProperty($entity, 'id');
94
+
95
+        $qb->delete($this->tableName)
96
+            ->where(
97
+                $qb->expr()->eq('id', $qb->createNamedParameter($entity->getId(), $idType))
98
+            );
99
+        $qb->execute();
100
+        return $entity;
101
+    }
102
+
103
+
104
+    /**
105
+     * Creates a new entry in the db from an entity
106
+     * @param Entity $entity the entity that should be created
107
+     * @return Entity the saved entity with the set id
108
+     * @since 14.0.0
109
+     * @suppress SqlInjectionChecker
110
+     */
111
+    public function insert(Entity $entity): Entity {
112
+        // get updated fields to save, fields have to be set using a setter to
113
+        // be saved
114
+        $properties = $entity->getUpdatedFields();
115
+
116
+        $qb = $this->db->getQueryBuilder();
117
+        $qb->insert($this->tableName);
118
+
119
+        // build the fields
120
+        foreach($properties as $property => $updated) {
121
+            $column = $entity->propertyToColumn($property);
122
+            $getter = 'get' . ucfirst($property);
123
+            $value = $entity->$getter();
124
+
125
+            $type = $this->getParameterTypeForProperty($entity, $property);
126
+            $qb->setValue($column, $qb->createNamedParameter($value, $type));
127
+        }
128
+
129
+        $qb->execute();
130
+
131
+        if($entity->id === null) {
132
+            // When autoincrement is used id is always an int
133
+            $entity->setId((int)$qb->getLastInsertId());
134
+        }
135
+
136
+        return $entity;
137
+    }
138
+
139
+    /**
140
+     * Tries to creates a new entry in the db from an entity and
141
+     * updates an existing entry if duplicate keys are detected
142
+     * by the database
143
+     *
144
+     * @param Entity $entity the entity that should be created/updated
145
+     * @return Entity the saved entity with the (new) id
146
+     * @throws \InvalidArgumentException if entity has no id
147
+     * @since 15.0.0
148
+     * @suppress SqlInjectionChecker
149
+     */
150
+    public function insertOrUpdate(Entity $entity): Entity {
151
+        try {
152
+            return $this->insert($entity);
153
+        } catch (UniqueConstraintViolationException $ex) {
154
+            return $this->update($entity);
155
+        }
156
+    }
157
+
158
+    /**
159
+     * Updates an entry in the db from an entity
160
+     * @throws \InvalidArgumentException if entity has no id
161
+     * @param Entity $entity the entity that should be created
162
+     * @return Entity the saved entity with the set id
163
+     * @since 14.0.0
164
+     * @suppress SqlInjectionChecker
165
+     */
166
+    public function update(Entity $entity): Entity {
167
+        // if entity wasn't changed it makes no sense to run a db query
168
+        $properties = $entity->getUpdatedFields();
169
+        if(\count($properties) === 0) {
170
+            return $entity;
171
+        }
172
+
173
+        // entity needs an id
174
+        $id = $entity->getId();
175
+        if($id === null){
176
+            throw new \InvalidArgumentException(
177
+                'Entity which should be updated has no id');
178
+        }
179
+
180
+        // get updated fields to save, fields have to be set using a setter to
181
+        // be saved
182
+        // do not update the id field
183
+        unset($properties['id']);
184
+
185
+        $qb = $this->db->getQueryBuilder();
186
+        $qb->update($this->tableName);
187
+
188
+        // build the fields
189
+        foreach($properties as $property => $updated) {
190
+            $column = $entity->propertyToColumn($property);
191
+            $getter = 'get' . ucfirst($property);
192
+            $value = $entity->$getter();
193
+
194
+            $type = $this->getParameterTypeForProperty($entity, $property);
195
+            $qb->set($column, $qb->createNamedParameter($value, $type));
196
+        }
197
+
198
+        $idType = $this->getParameterTypeForProperty($entity, 'id');
199
+
200
+        $qb->where(
201
+            $qb->expr()->eq('id', $qb->createNamedParameter($id, $idType))
202
+        );
203
+        $qb->execute();
204
+
205
+        return $entity;
206
+    }
207
+
208
+    /**
209
+     * Returns the type parameter for the QueryBuilder for a specific property
210
+     * of the $entity
211
+     *
212
+     * @param Entity $entity   The entity to get the types from
213
+     * @param string $property The property of $entity to get the type for
214
+     * @return int
215
+     * @since 16.0.0
216
+     */
217
+    protected function getParameterTypeForProperty(Entity $entity, string $property): int {
218
+        $types = $entity->getFieldTypes();
219
+
220
+        if(!isset($types[ $property ])) {
221
+            return IQueryBuilder::PARAM_STR;
222
+        }
223
+
224
+        switch($types[ $property ]) {
225
+            case 'int':
226
+            case 'integer':
227
+                return IQueryBuilder::PARAM_INT;
228
+            case 'string':
229
+                return IQueryBuilder::PARAM_STR;
230
+            case 'bool':
231
+            case 'boolean':
232
+                return IQueryBuilder::PARAM_BOOL;
233
+        }
234
+
235
+        return IQueryBuilder::PARAM_STR;
236
+    }
237
+
238
+    /**
239
+     * Returns an db result and throws exceptions when there are more or less
240
+     * results
241
+     *
242
+     * @see findEntity
243
+     *
244
+     * @param IQueryBuilder $query
245
+     * @throws DoesNotExistException if the item does not exist
246
+     * @throws MultipleObjectsReturnedException if more than one item exist
247
+     * @return array the result as row
248
+     * @since 14.0.0
249
+     */
250
+    protected function findOneQuery(IQueryBuilder $query): array {
251
+        $cursor = $query->execute();
252
+
253
+        $row = $cursor->fetch();
254
+        if($row === false) {
255
+            $cursor->closeCursor();
256
+            $msg = $this->buildDebugMessage(
257
+                'Did expect one result but found none when executing', $query
258
+            );
259
+            throw new DoesNotExistException($msg);
260
+        }
261
+
262
+        $row2 = $cursor->fetch();
263
+        $cursor->closeCursor();
264
+        if($row2 !== false) {
265
+            $msg = $this->buildDebugMessage(
266
+                'Did not expect more than one result when executing', $query
267
+            );
268
+            throw new MultipleObjectsReturnedException($msg);
269
+        }
270
+
271
+        return $row;
272
+    }
273
+
274
+    /**
275
+     * @param string $msg
276
+     * @param IQueryBuilder $sql
277
+     * @return string
278
+     * @since 14.0.0
279
+     */
280
+    private function buildDebugMessage(string $msg, IQueryBuilder $sql): string {
281
+        return $msg .
282
+            ': query "' . $sql->getSQL() . '"; ';
283
+    }
284
+
285
+
286
+    /**
287
+     * Creates an entity from a row. Automatically determines the entity class
288
+     * from the current mapper name (MyEntityMapper -> MyEntity)
289
+     *
290
+     * @param array $row the row which should be converted to an entity
291
+     * @return Entity the entity
292
+     * @since 14.0.0
293
+     */
294
+    protected function mapRowToEntity(array $row): Entity {
295
+        return \call_user_func($this->entityClass .'::fromRow', $row);
296
+    }
297
+
298
+
299
+    /**
300
+     * Runs a sql query and returns an array of entities
301
+     *
302
+     * @param IQueryBuilder $query
303
+     * @return Entity[] all fetched entities
304
+     * @since 14.0.0
305
+     */
306
+    protected function findEntities(IQueryBuilder $query): array {
307
+        $cursor = $query->execute();
308
+
309
+        $entities = [];
310
+
311
+        while($row = $cursor->fetch()){
312
+            $entities[] = $this->mapRowToEntity($row);
313
+        }
314
+
315
+        $cursor->closeCursor();
316
+
317
+        return $entities;
318
+    }
319
+
320
+
321
+    /**
322
+     * Returns an db result and throws exceptions when there are more or less
323
+     * results
324
+     *
325
+     * @param IQueryBuilder $query
326
+     * @throws DoesNotExistException if the item does not exist
327
+     * @throws MultipleObjectsReturnedException if more than one item exist
328
+     * @return Entity the entity
329
+     * @since 14.0.0
330
+     */
331
+    protected function findEntity(IQueryBuilder $query): Entity {
332
+        return $this->mapRowToEntity($this->findOneQuery($query));
333
+    }
334 334
 
335 335
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
 	 * mapped to queries without using sql
59 59
 	 * @since 14.0.0
60 60
 	 */
61
-	public function __construct(IDBConnection $db, string $tableName, string $entityClass=null) {
61
+	public function __construct(IDBConnection $db, string $tableName, string $entityClass = null) {
62 62
 		$this->db = $db;
63 63
 		$this->tableName = $tableName;
64 64
 
65 65
 		// if not given set the entity name to the class without the mapper part
66 66
 		// cache it here for later use since reflection is slow
67
-		if($entityClass === null) {
67
+		if ($entityClass === null) {
68 68
 			$this->entityClass = str_replace('Mapper', '', \get_class($this));
69 69
 		} else {
70 70
 			$this->entityClass = $entityClass;
@@ -117,9 +117,9 @@  discard block
 block discarded – undo
117 117
 		$qb->insert($this->tableName);
118 118
 
119 119
 		// build the fields
120
-		foreach($properties as $property => $updated) {
120
+		foreach ($properties as $property => $updated) {
121 121
 			$column = $entity->propertyToColumn($property);
122
-			$getter = 'get' . ucfirst($property);
122
+			$getter = 'get'.ucfirst($property);
123 123
 			$value = $entity->$getter();
124 124
 
125 125
 			$type = $this->getParameterTypeForProperty($entity, $property);
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 
129 129
 		$qb->execute();
130 130
 
131
-		if($entity->id === null) {
131
+		if ($entity->id === null) {
132 132
 			// When autoincrement is used id is always an int
133
-			$entity->setId((int)$qb->getLastInsertId());
133
+			$entity->setId((int) $qb->getLastInsertId());
134 134
 		}
135 135
 
136 136
 		return $entity;
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
 	public function update(Entity $entity): Entity {
167 167
 		// if entity wasn't changed it makes no sense to run a db query
168 168
 		$properties = $entity->getUpdatedFields();
169
-		if(\count($properties) === 0) {
169
+		if (\count($properties) === 0) {
170 170
 			return $entity;
171 171
 		}
172 172
 
173 173
 		// entity needs an id
174 174
 		$id = $entity->getId();
175
-		if($id === null){
175
+		if ($id === null) {
176 176
 			throw new \InvalidArgumentException(
177 177
 				'Entity which should be updated has no id');
178 178
 		}
@@ -186,9 +186,9 @@  discard block
 block discarded – undo
186 186
 		$qb->update($this->tableName);
187 187
 
188 188
 		// build the fields
189
-		foreach($properties as $property => $updated) {
189
+		foreach ($properties as $property => $updated) {
190 190
 			$column = $entity->propertyToColumn($property);
191
-			$getter = 'get' . ucfirst($property);
191
+			$getter = 'get'.ucfirst($property);
192 192
 			$value = $entity->$getter();
193 193
 
194 194
 			$type = $this->getParameterTypeForProperty($entity, $property);
@@ -217,11 +217,11 @@  discard block
 block discarded – undo
217 217
 	protected function getParameterTypeForProperty(Entity $entity, string $property): int {
218 218
 		$types = $entity->getFieldTypes();
219 219
 
220
-		if(!isset($types[ $property ])) {
220
+		if (!isset($types[$property])) {
221 221
 			return IQueryBuilder::PARAM_STR;
222 222
 		}
223 223
 
224
-		switch($types[ $property ]) {
224
+		switch ($types[$property]) {
225 225
 			case 'int':
226 226
 			case 'integer':
227 227
 				return IQueryBuilder::PARAM_INT;
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 		$cursor = $query->execute();
252 252
 
253 253
 		$row = $cursor->fetch();
254
-		if($row === false) {
254
+		if ($row === false) {
255 255
 			$cursor->closeCursor();
256 256
 			$msg = $this->buildDebugMessage(
257 257
 				'Did expect one result but found none when executing', $query
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 
262 262
 		$row2 = $cursor->fetch();
263 263
 		$cursor->closeCursor();
264
-		if($row2 !== false) {
264
+		if ($row2 !== false) {
265 265
 			$msg = $this->buildDebugMessage(
266 266
 				'Did not expect more than one result when executing', $query
267 267
 			);
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
 	 * @since 14.0.0
279 279
 	 */
280 280
 	private function buildDebugMessage(string $msg, IQueryBuilder $sql): string {
281
-		return $msg .
282
-			': query "' . $sql->getSQL() . '"; ';
281
+		return $msg.
282
+			': query "'.$sql->getSQL().'"; ';
283 283
 	}
284 284
 
285 285
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @since 14.0.0
293 293
 	 */
294 294
 	protected function mapRowToEntity(array $row): Entity {
295
-		return \call_user_func($this->entityClass .'::fromRow', $row);
295
+		return \call_user_func($this->entityClass.'::fromRow', $row);
296 296
 	}
297 297
 
298 298
 
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 
309 309
 		$entities = [];
310 310
 
311
-		while($row = $cursor->fetch()){
311
+		while ($row = $cursor->fetch()) {
312 312
 			$entities[] = $this->mapRowToEntity($row);
313 313
 		}
314 314
 
Please login to merge, or discard this patch.