1
0
mirror of synced 2025-01-10 11:07:10 +03:00

Merge pull request #911 from goatherd/fix-foreach-as-style

fix foreach coding style
This commit is contained in:
Steve Müller 2014-01-14 14:50:33 -08:00
commit cf43edd6a1
8 changed files with 22 additions and 22 deletions

View File

@ -149,7 +149,7 @@ collection, which means we can compute this value at runtime:
public function getBalance()
{
$balance = 0;
foreach ($this->entries AS $entry) {
foreach ($this->entries as $entry) {
$balance += $entry->getAmount();
}
return $balance;

View File

@ -130,7 +130,7 @@ implementation is:
{
$parent = null;
$parentName = null;
foreach ($this->_getQueryComponents() AS $dqlAlias => $qComp) {
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
if ($qComp['parent'] === null && $qComp['nestingLevel'] == 0) {
$parent = $qComp;
$parentName = $dqlAlias;

View File

@ -38,7 +38,7 @@ is allowed to:
$orderLimit = $this->customer->getOrderLimit();
$amount = 0;
foreach ($this->orderLines AS $line) {
foreach ($this->orderLines as $line) {
$amount += $line->getAmount();
}

View File

@ -76,7 +76,7 @@ with the batching strategy that was already used for bulk inserts:
$i = 0;
$q = $em->createQuery('select u from MyProject\Model\User u');
$iterableResult = $q->iterate();
foreach($iterableResult AS $row) {
foreach ($iterableResult as $row) {
$user = $row[0];
$user->increaseCredit();
$user->calculateNewBonuses();
@ -162,7 +162,7 @@ problems using the following approach:
<?php
$q = $this->_em->createQuery('select u from MyProject\Model\User u');
$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
// detach from Doctrine, so that it can be Garbage-Collected immediately

View File

@ -584,23 +584,23 @@ mentioned sets. See this example:
$em = $eventArgs->getEntityManager();
$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) {
}
}

View File

@ -468,7 +468,7 @@ removed from the system:
<?php
$user = $em->find('User', $deleteUserId);
foreach ($user->getAuthoredComments() AS $comment) {
foreach ($user->getAuthoredComments() as $comment) {
$em->remove($comment);
}
$em->remove($user);

View File

@ -143,7 +143,7 @@ your code. See the following code:
// accessing the comments as an iterator triggers the lazy-load
// retrieving ALL the comments of this article from the database
// using a single SELECT statement
foreach ($article->getComments() AS $comment) {
foreach ($article->getComments() as $comment) {
echo $comment->getText() . "\n\n";
}

View File

@ -1054,7 +1054,7 @@ like this:
$bug->setCreated(new DateTime("now"));
$bug->setStatus("OPEN");
foreach ($productIds AS $productId) {
foreach ($productIds as $productId) {
$product = $entityManager->find("Product", $productId);
$bug->assignToProduct($product);
}
@ -1108,11 +1108,11 @@ the first read-only use-case:
$query->setMaxResults(30);
$bugs = $query->getResult();
foreach($bugs AS $bug) {
foreach ($bugs as $bug) {
echo $bug->getDescription()." - ".$bug->getCreated()->format('d.m.Y')."\n";
echo " Reported by: ".$bug->getReporter()->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 "\n";
@ -1194,11 +1194,11 @@ can rewrite our code:
$query = $entityManager->createQuery($dql);
$bugs = $query->getArrayResult();
foreach ($bugs AS $bug) {
foreach ($bugs as $bug) {
echo $bug['description'] . " - " . $bug['created']->format('d.m.Y')."\n";
echo " Reported by: ".$bug['reporter']['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 "\n";
@ -1312,7 +1312,7 @@ and usage of bound parameters:
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";
}
@ -1337,7 +1337,7 @@ grouped by product:
"JOIN b.products p WHERE b.status = 'OPEN' GROUP BY p.id";
$productBugs = $entityManager->createQuery($dql)->getScalarResult();
foreach($productBugs as $productBug) {
foreach ($productBugs as $productBug) {
echo $productBug['name']." has " . $productBug['openBugs'] . " open bugs!\n";
}
@ -1417,7 +1417,7 @@ example querying for all closed bugs:
$bugs = $entityManager->getRepository('Bug')
->findBy(array('status' => 'CLOSED'));
foreach ($bugs AS $bug) {
foreach ($bugs as $bug) {
// 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();
foreach($bugs AS $bug) {
foreach ($bugs as $bug) {
echo $bug->getDescription()." - ".$bug->getCreated()->format('d.m.Y')."\n";
echo " Reported by: ".$bug->getReporter()->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 "\n";