summaryrefslogtreecommitdiffstats
path: root/lib/public/AppFramework/Db/QBMapper.php
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-04-10 14:19:56 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-04-10 14:19:56 +0200
commitcaff1023ea72bb2ea94130e18a2a6e2ccf819e5f (patch)
tree186d494c2aea5dea7255d3584ef5d595fc6e6194 /lib/public/AppFramework/Db/QBMapper.php
parentedf8ce32cffdb920e8171207b342abbd7f1fbe73 (diff)
downloadnextcloud-server-caff1023ea72bb2ea94130e18a2a6e2ccf819e5f.tar.gz
nextcloud-server-caff1023ea72bb2ea94130e18a2a6e2ccf819e5f.zip
Format control structures, classes, methods and function
To continue this formatting madness, here's a tiny patch that adds unified formatting for control structures like if and loops as well as classes, their methods and anonymous functions. This basically forces the constructs to start on the same line. This is not exactly what PSR2 wants, but I think we can have a few exceptions with "our" style. The starting of braces on the same line is pracrically standard for our code. This also removes and empty lines from method/function bodies at the beginning and end. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/public/AppFramework/Db/QBMapper.php')
-rw-r--r--lib/public/AppFramework/Db/QBMapper.php23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/public/AppFramework/Db/QBMapper.php b/lib/public/AppFramework/Db/QBMapper.php
index c7b4b877651..9b396965706 100644
--- a/lib/public/AppFramework/Db/QBMapper.php
+++ b/lib/public/AppFramework/Db/QBMapper.php
@@ -64,7 +64,7 @@ abstract class QBMapper {
// if not given set the entity name to the class without the mapper part
// cache it here for later use since reflection is slow
- if($entityClass === null) {
+ if ($entityClass === null) {
$this->entityClass = str_replace('Mapper', '', \get_class($this));
} else {
$this->entityClass = $entityClass;
@@ -117,7 +117,7 @@ abstract class QBMapper {
$qb->insert($this->tableName);
// build the fields
- foreach($properties as $property => $updated) {
+ foreach ($properties as $property => $updated) {
$column = $entity->propertyToColumn($property);
$getter = 'get' . ucfirst($property);
$value = $entity->$getter();
@@ -128,7 +128,7 @@ abstract class QBMapper {
$qb->execute();
- if($entity->id === null) {
+ if ($entity->id === null) {
// When autoincrement is used id is always an int
$entity->setId((int)$qb->getLastInsertId());
}
@@ -166,13 +166,13 @@ abstract class QBMapper {
public function update(Entity $entity): Entity {
// if entity wasn't changed it makes no sense to run a db query
$properties = $entity->getUpdatedFields();
- if(\count($properties) === 0) {
+ if (\count($properties) === 0) {
return $entity;
}
// entity needs an id
$id = $entity->getId();
- if($id === null){
+ if ($id === null) {
throw new \InvalidArgumentException(
'Entity which should be updated has no id');
}
@@ -186,7 +186,7 @@ abstract class QBMapper {
$qb->update($this->tableName);
// build the fields
- foreach($properties as $property => $updated) {
+ foreach ($properties as $property => $updated) {
$column = $entity->propertyToColumn($property);
$getter = 'get' . ucfirst($property);
$value = $entity->$getter();
@@ -217,11 +217,11 @@ abstract class QBMapper {
protected function getParameterTypeForProperty(Entity $entity, string $property): int {
$types = $entity->getFieldTypes();
- if(!isset($types[ $property ])) {
+ if (!isset($types[ $property ])) {
return IQueryBuilder::PARAM_STR;
}
- switch($types[ $property ]) {
+ switch ($types[ $property ]) {
case 'int':
case 'integer':
return IQueryBuilder::PARAM_INT;
@@ -251,7 +251,7 @@ abstract class QBMapper {
$cursor = $query->execute();
$row = $cursor->fetch();
- if($row === false) {
+ if ($row === false) {
$cursor->closeCursor();
$msg = $this->buildDebugMessage(
'Did expect one result but found none when executing', $query
@@ -261,7 +261,7 @@ abstract class QBMapper {
$row2 = $cursor->fetch();
$cursor->closeCursor();
- if($row2 !== false) {
+ if ($row2 !== false) {
$msg = $this->buildDebugMessage(
'Did not expect more than one result when executing', $query
);
@@ -308,7 +308,7 @@ abstract class QBMapper {
$entities = [];
- while($row = $cursor->fetch()){
+ while ($row = $cursor->fetch()) {
$entities[] = $this->mapRowToEntity($row);
}
@@ -331,5 +331,4 @@ abstract class QBMapper {
protected function findEntity(IQueryBuilder $query): Entity {
return $this->mapRowToEntity($this->findOneQuery($query));
}
-
}