Merge pull request #911 from goatherd/fix-foreach-as-style
fix foreach coding style
This commit is contained in:
commit
cf43edd6a1
@ -149,7 +149,7 @@ collection, which means we can compute this value at runtime:
|
|||||||
public function getBalance()
|
public function getBalance()
|
||||||
{
|
{
|
||||||
$balance = 0;
|
$balance = 0;
|
||||||
foreach ($this->entries AS $entry) {
|
foreach ($this->entries as $entry) {
|
||||||
$balance += $entry->getAmount();
|
$balance += $entry->getAmount();
|
||||||
}
|
}
|
||||||
return $balance;
|
return $balance;
|
||||||
|
@ -130,7 +130,7 @@ implementation is:
|
|||||||
{
|
{
|
||||||
$parent = null;
|
$parent = null;
|
||||||
$parentName = null;
|
$parentName = null;
|
||||||
foreach ($this->_getQueryComponents() AS $dqlAlias => $qComp) {
|
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
|
||||||
if ($qComp['parent'] === null && $qComp['nestingLevel'] == 0) {
|
if ($qComp['parent'] === null && $qComp['nestingLevel'] == 0) {
|
||||||
$parent = $qComp;
|
$parent = $qComp;
|
||||||
$parentName = $dqlAlias;
|
$parentName = $dqlAlias;
|
||||||
|
@ -38,7 +38,7 @@ is allowed to:
|
|||||||
$orderLimit = $this->customer->getOrderLimit();
|
$orderLimit = $this->customer->getOrderLimit();
|
||||||
|
|
||||||
$amount = 0;
|
$amount = 0;
|
||||||
foreach ($this->orderLines AS $line) {
|
foreach ($this->orderLines as $line) {
|
||||||
$amount += $line->getAmount();
|
$amount += $line->getAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ with the batching strategy that was already used for bulk inserts:
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
$q = $em->createQuery('select u from MyProject\Model\User u');
|
$q = $em->createQuery('select u from MyProject\Model\User u');
|
||||||
$iterableResult = $q->iterate();
|
$iterableResult = $q->iterate();
|
||||||
foreach($iterableResult AS $row) {
|
foreach ($iterableResult as $row) {
|
||||||
$user = $row[0];
|
$user = $row[0];
|
||||||
$user->increaseCredit();
|
$user->increaseCredit();
|
||||||
$user->calculateNewBonuses();
|
$user->calculateNewBonuses();
|
||||||
@ -162,7 +162,7 @@ problems using the following approach:
|
|||||||
<?php
|
<?php
|
||||||
$q = $this->_em->createQuery('select u from MyProject\Model\User u');
|
$q = $this->_em->createQuery('select u from MyProject\Model\User u');
|
||||||
$iterableResult = $q->iterate();
|
$iterableResult = $q->iterate();
|
||||||
foreach ($iterableResult AS $row) {
|
foreach ($iterableResult as $row) {
|
||||||
// do stuff with the data in the row, $row[0] is always the object
|
// do stuff with the data in the row, $row[0] is always the object
|
||||||
|
|
||||||
// detach from Doctrine, so that it can be Garbage-Collected immediately
|
// detach from Doctrine, so that it can be Garbage-Collected immediately
|
||||||
|
@ -584,23 +584,23 @@ mentioned sets. See this example:
|
|||||||
$em = $eventArgs->getEntityManager();
|
$em = $eventArgs->getEntityManager();
|
||||||
$uow = $em->getUnitOfWork();
|
$uow = $em->getUnitOfWork();
|
||||||
|
|
||||||
foreach ($uow->getScheduledEntityInsertions() AS $entity) {
|
foreach ($uow->getScheduledEntityInsertions() as $entity) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($uow->getScheduledEntityUpdates() AS $entity) {
|
foreach ($uow->getScheduledEntityUpdates() as $entity) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($uow->getScheduledEntityDeletions() AS $entity) {
|
foreach ($uow->getScheduledEntityDeletions() as $entity) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($uow->getScheduledCollectionDeletions() AS $col) {
|
foreach ($uow->getScheduledCollectionDeletions() as $col) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($uow->getScheduledCollectionUpdates() AS $col) {
|
foreach ($uow->getScheduledCollectionUpdates() as $col) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,7 @@ removed from the system:
|
|||||||
<?php
|
<?php
|
||||||
$user = $em->find('User', $deleteUserId);
|
$user = $em->find('User', $deleteUserId);
|
||||||
|
|
||||||
foreach ($user->getAuthoredComments() AS $comment) {
|
foreach ($user->getAuthoredComments() as $comment) {
|
||||||
$em->remove($comment);
|
$em->remove($comment);
|
||||||
}
|
}
|
||||||
$em->remove($user);
|
$em->remove($user);
|
||||||
|
@ -143,7 +143,7 @@ your code. See the following code:
|
|||||||
// accessing the comments as an iterator triggers the lazy-load
|
// accessing the comments as an iterator triggers the lazy-load
|
||||||
// retrieving ALL the comments of this article from the database
|
// retrieving ALL the comments of this article from the database
|
||||||
// using a single SELECT statement
|
// using a single SELECT statement
|
||||||
foreach ($article->getComments() AS $comment) {
|
foreach ($article->getComments() as $comment) {
|
||||||
echo $comment->getText() . "\n\n";
|
echo $comment->getText() . "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,7 +1054,7 @@ like this:
|
|||||||
$bug->setCreated(new DateTime("now"));
|
$bug->setCreated(new DateTime("now"));
|
||||||
$bug->setStatus("OPEN");
|
$bug->setStatus("OPEN");
|
||||||
|
|
||||||
foreach ($productIds AS $productId) {
|
foreach ($productIds as $productId) {
|
||||||
$product = $entityManager->find("Product", $productId);
|
$product = $entityManager->find("Product", $productId);
|
||||||
$bug->assignToProduct($product);
|
$bug->assignToProduct($product);
|
||||||
}
|
}
|
||||||
@ -1108,11 +1108,11 @@ the first read-only use-case:
|
|||||||
$query->setMaxResults(30);
|
$query->setMaxResults(30);
|
||||||
$bugs = $query->getResult();
|
$bugs = $query->getResult();
|
||||||
|
|
||||||
foreach($bugs AS $bug) {
|
foreach ($bugs as $bug) {
|
||||||
echo $bug->getDescription()." - ".$bug->getCreated()->format('d.m.Y')."\n";
|
echo $bug->getDescription()." - ".$bug->getCreated()->format('d.m.Y')."\n";
|
||||||
echo " Reported by: ".$bug->getReporter()->getName()."\n";
|
echo " Reported by: ".$bug->getReporter()->getName()."\n";
|
||||||
echo " Assigned to: ".$bug->getEngineer()->getName()."\n";
|
echo " Assigned to: ".$bug->getEngineer()->getName()."\n";
|
||||||
foreach($bug->getProducts() AS $product) {
|
foreach ($bug->getProducts() as $product) {
|
||||||
echo " Platform: ".$product->getName()."\n";
|
echo " Platform: ".$product->getName()."\n";
|
||||||
}
|
}
|
||||||
echo "\n";
|
echo "\n";
|
||||||
@ -1194,11 +1194,11 @@ can rewrite our code:
|
|||||||
$query = $entityManager->createQuery($dql);
|
$query = $entityManager->createQuery($dql);
|
||||||
$bugs = $query->getArrayResult();
|
$bugs = $query->getArrayResult();
|
||||||
|
|
||||||
foreach ($bugs AS $bug) {
|
foreach ($bugs as $bug) {
|
||||||
echo $bug['description'] . " - " . $bug['created']->format('d.m.Y')."\n";
|
echo $bug['description'] . " - " . $bug['created']->format('d.m.Y')."\n";
|
||||||
echo " Reported by: ".$bug['reporter']['name']."\n";
|
echo " Reported by: ".$bug['reporter']['name']."\n";
|
||||||
echo " Assigned to: ".$bug['engineer']['name']."\n";
|
echo " Assigned to: ".$bug['engineer']['name']."\n";
|
||||||
foreach($bug['products'] AS $product) {
|
foreach ($bug['products'] as $product) {
|
||||||
echo " Platform: ".$product['name']."\n";
|
echo " Platform: ".$product['name']."\n";
|
||||||
}
|
}
|
||||||
echo "\n";
|
echo "\n";
|
||||||
@ -1312,7 +1312,7 @@ and usage of bound parameters:
|
|||||||
|
|
||||||
echo "You have created or assigned to " . count($myBugs) . " open bugs:\n\n";
|
echo "You have created or assigned to " . count($myBugs) . " open bugs:\n\n";
|
||||||
|
|
||||||
foreach ($myBugs AS $bug) {
|
foreach ($myBugs as $bug) {
|
||||||
echo $bug->getId() . " - " . $bug->getDescription()."\n";
|
echo $bug->getId() . " - " . $bug->getDescription()."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1337,7 +1337,7 @@ grouped by product:
|
|||||||
"JOIN b.products p WHERE b.status = 'OPEN' GROUP BY p.id";
|
"JOIN b.products p WHERE b.status = 'OPEN' GROUP BY p.id";
|
||||||
$productBugs = $entityManager->createQuery($dql)->getScalarResult();
|
$productBugs = $entityManager->createQuery($dql)->getScalarResult();
|
||||||
|
|
||||||
foreach($productBugs as $productBug) {
|
foreach ($productBugs as $productBug) {
|
||||||
echo $productBug['name']." has " . $productBug['openBugs'] . " open bugs!\n";
|
echo $productBug['name']." has " . $productBug['openBugs'] . " open bugs!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1417,7 +1417,7 @@ example querying for all closed bugs:
|
|||||||
$bugs = $entityManager->getRepository('Bug')
|
$bugs = $entityManager->getRepository('Bug')
|
||||||
->findBy(array('status' => 'CLOSED'));
|
->findBy(array('status' => 'CLOSED'));
|
||||||
|
|
||||||
foreach ($bugs AS $bug) {
|
foreach ($bugs as $bug) {
|
||||||
// do stuff
|
// do stuff
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1519,11 +1519,11 @@ As an example here is the code of the first use case "List of Bugs":
|
|||||||
|
|
||||||
$bugs = $entityManager->getRepository('Bug')->getRecentBugs();
|
$bugs = $entityManager->getRepository('Bug')->getRecentBugs();
|
||||||
|
|
||||||
foreach($bugs AS $bug) {
|
foreach ($bugs as $bug) {
|
||||||
echo $bug->getDescription()." - ".$bug->getCreated()->format('d.m.Y')."\n";
|
echo $bug->getDescription()." - ".$bug->getCreated()->format('d.m.Y')."\n";
|
||||||
echo " Reported by: ".$bug->getReporter()->getName()."\n";
|
echo " Reported by: ".$bug->getReporter()->getName()."\n";
|
||||||
echo " Assigned to: ".$bug->getEngineer()->getName()."\n";
|
echo " Assigned to: ".$bug->getEngineer()->getName()."\n";
|
||||||
foreach($bug->getProducts() AS $product) {
|
foreach ($bug->getProducts() as $product) {
|
||||||
echo " Platform: ".$product->getName()."\n";
|
echo " Platform: ".$product->getName()."\n";
|
||||||
}
|
}
|
||||||
echo "\n";
|
echo "\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user