Skip to content

Commit

Permalink
code style. FOREACH
Browse files Browse the repository at this point in the history
  • Loading branch information
mohorev committed Mar 3, 2014
1 parent b2f1b00 commit 95ea1c2
Show file tree
Hide file tree
Showing 59 changed files with 141 additions and 141 deletions.
2 changes: 1 addition & 1 deletion docs/internals/view-code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use yii\widgets\ActiveForm;
$this->title = 'Posts';
?>
<!-- Separate PHP blocks are preferred for foreach, for, if etc. -->
<?php foreach($posts as $post): ?>
<?php foreach ($posts as $post): ?>
<!-- Note indentation level here. -->
<h2><?= Html::encode($post['title']) ?></h2>
<p><?= Html::encode($post['shortDescription']) ?></p>
Expand Down
4 changes: 2 additions & 2 deletions extensions/apidoc/apidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $composerAutoload = [
__DIR__ . '/../../autoload.php', // script is installed as a composer binary
];
$vendorPath = null;
foreach($composerAutoload as $autoload) {
foreach ($composerAutoload as $autoload) {
if (file_exists($autoload)) {
require($autoload);
$vendorPath = dirname($autoload);
Expand All @@ -27,7 +27,7 @@ $yiiDirs = [
__DIR__ . '/vendor/yiisoft/yii2', // standalone with "composer install" run
__DIR__ . '/../../yiisoft/yii2', // script is installed as a composer binary
];
foreach($yiiDirs as $dir) {
foreach ($yiiDirs as $dir) {
if (file_exists($dir . '/Yii.php')) {
require($dir . '/Yii.php');
break;
Expand Down
8 changes: 4 additions & 4 deletions extensions/apidoc/commands/RenderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function actionIndex(array $sourceDirs, $targetDir)

$this->stdout('Searching files to process... ');
$files = [];
foreach($sourceDirs as $source) {
foreach($this->findFiles($source) as $fileName) {
foreach ($sourceDirs as $source) {
foreach ($this->findFiles($source) as $fileName) {
$files[$fileName] = $fileName;
}
}
Expand All @@ -80,7 +80,7 @@ public function actionIndex(array $sourceDirs, $targetDir)
$this->stdout('done.' . PHP_EOL, Console::FG_GREEN);

$this->stdout('Checking for updated files... ');
foreach($context->files as $file => $sha) {
foreach ($context->files as $file => $sha) {
if (sha1_file($file) === $sha) {
unset($files[$file]);
}
Expand All @@ -92,7 +92,7 @@ public function actionIndex(array $sourceDirs, $targetDir)
$this->stdout($fileCount . ' file' . ($fileCount == 1 ? '' : 's') . ' to update.' . PHP_EOL);
Console::startProgress(0, $fileCount, 'Processing files... ', false);
$done = 0;
foreach($files as $file) {
foreach ($files as $file) {
$context->addFile($file);
Console::updateProgress(++$done, $fileCount);
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/apidoc/models/BaseDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct($reflector = null, $context = null, $config = [])
$this->phpDocContext = $docblock->getContext();

$this->tags = $docblock->getTags();
foreach($this->tags as $i => $tag) {
foreach ($this->tags as $i => $tag) {
if ($tag instanceof SinceTag) {
$this->since = $tag->getVersion();
unset($this->tags[$i]);
Expand Down
12 changes: 6 additions & 6 deletions extensions/apidoc/models/ClassDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function findSubject($subjectName)
if (($subject = parent::findSubject($subjectName)) !== null) {
return $subject;
}
foreach($this->events as $name => $event) {
foreach ($this->events as $name => $event) {
if ($subjectName == $name) {
return $event;
}
}
foreach($this->constants as $name => $constant) {
foreach ($this->constants as $name => $constant) {
if ($subjectName == $name) {
return $constant;
}
Expand All @@ -64,7 +64,7 @@ public function findSubject($subjectName)
public function getNativeEvents()
{
$events = [];
foreach($this->events as $name => $event) {
foreach ($this->events as $name => $event) {
if ($event->definedBy != $this->name) {
continue;
}
Expand Down Expand Up @@ -93,13 +93,13 @@ public function __construct($reflector = null, $context = null, $config = [])
$this->isAbstract = $reflector->isAbstract();
$this->isFinal = $reflector->isFinal();

foreach($reflector->getInterfaces() as $interface) {
foreach ($reflector->getInterfaces() as $interface) {
$this->interfaces[] = ltrim($interface, '\\');
}
foreach($reflector->getTraits() as $trait) {
foreach ($reflector->getTraits() as $trait) {
$this->traits[] = ltrim($trait, '\\');
}
foreach($reflector->getConstants() as $constantReflector) {
foreach ($reflector->getConstants() as $constantReflector) {
$docblock = $constantReflector->getDocBlock();
if ($docblock !== null && count($docblock->getTagsByName('event')) > 0) {
$event = new EventDoc($constantReflector);
Expand Down
32 changes: 16 additions & 16 deletions extensions/apidoc/models/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public function addFile($fileName)
$reflection = new FileReflector($fileName, true);
$reflection->process();

foreach($reflection->getClasses() as $class) {
foreach ($reflection->getClasses() as $class) {
$class = new ClassDoc($class, $this, ['sourceFile' => $fileName]);
$this->classes[$class->name] = $class;
}
foreach($reflection->getInterfaces() as $interface) {
foreach ($reflection->getInterfaces() as $interface) {
$interface = new InterfaceDoc($interface, $this, ['sourceFile' => $fileName]);
$this->interfaces[$interface->name] = $interface;
}
foreach($reflection->getTraits() as $trait) {
foreach ($reflection->getTraits() as $trait) {
$trait = new TraitDoc($trait, $this, ['sourceFile' => $fileName]);
$this->traits[$trait->name] = $trait;
}
Expand All @@ -74,33 +74,33 @@ public function addFile($fileName)
public function updateReferences()
{
// update all subclass references
foreach($this->classes as $class) {
foreach ($this->classes as $class) {
$className = $class->name;
while (isset($this->classes[$class->parentClass])) {
$class = $this->classes[$class->parentClass];
$class->subclasses[] = $className;
}
}
// update interfaces of subclasses
foreach($this->classes as $class) {
foreach ($this->classes as $class) {
$this->updateSubclassInferfacesTraits($class);
}
// update implementedBy and usedBy for interfaces and traits
foreach($this->classes as $class) {
foreach($class->traits as $trait) {
foreach ($this->classes as $class) {
foreach ($class->traits as $trait) {
if (isset($this->traits[$trait])) {
$trait = $this->traits[$trait];
$trait->usedBy[] = $class->name;
$class->properties = array_merge($trait->properties, $class->properties);
$class->methods = array_merge($trait->methods, $class->methods);
}
}
foreach($class->interfaces as $interface) {
foreach ($class->interfaces as $interface) {
if (isset($this->interfaces[$interface])) {
$this->interfaces[$interface]->implementedBy[] = $class->name;
if ($class->isAbstract) {
// add not implemented interface methods
foreach($this->interfaces[$interface]->methods as $method) {
foreach ($this->interfaces[$interface]->methods as $method) {
if (!isset($class->methods[$method->name])) {
$class->methods[$method->name] = $method;
}
Expand All @@ -110,11 +110,11 @@ public function updateReferences()
}
}
// inherit properties, methods, contants and events to subclasses
foreach($this->classes as $class) {
foreach ($this->classes as $class) {
$this->updateSubclassInheritance($class);
}
// add properties from getters and setters
foreach($this->classes as $class) {
foreach ($this->classes as $class) {
$this->handlePropertyFeature($class);
}

Expand All @@ -127,7 +127,7 @@ public function updateReferences()
*/
protected function updateSubclassInferfacesTraits($class)
{
foreach($class->subclasses as $subclass) {
foreach ($class->subclasses as $subclass) {
$subclass = $this->classes[$subclass];
$subclass->interfaces = array_unique(array_merge($subclass->interfaces, $class->interfaces));
$subclass->traits = array_unique(array_merge($subclass->traits, $class->traits));
Expand All @@ -141,7 +141,7 @@ protected function updateSubclassInferfacesTraits($class)
*/
protected function updateSubclassInheritance($class)
{
foreach($class->subclasses as $subclass) {
foreach ($class->subclasses as $subclass) {
$subclass = $this->classes[$subclass];
$subclass->events = array_merge($class->events, $subclass->events);
$subclass->constants = array_merge($class->constants, $subclass->constants);
Expand All @@ -160,7 +160,7 @@ protected function handlePropertyFeature($class)
if (!$this->isSubclassOf($class, 'yii\base\Object')) {
return;
}
foreach($class->getPublicMethods() as $name => $method) {
foreach ($class->getPublicMethods() as $name => $method) {
if ($method->isStatic) {
continue;
}
Expand Down Expand Up @@ -232,7 +232,7 @@ protected function handlePropertyFeature($class)
*/
private function paramsOptional($method, $number = 0)
{
foreach($method->params as $param) {
foreach ($method->params as $param) {
if (!$param->isOptional && $number-- <= 0) {
return false;
}
Expand All @@ -246,7 +246,7 @@ private function paramsOptional($method, $number = 0)
*/
private function getFirstNotOptionalParameter($method)
{
foreach($method->params as $param) {
foreach ($method->params as $param) {
if (!$param->isOptional) {
return $param;
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/apidoc/models/EventDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($reflector = null, $context = null, $config = [])
return;
}

foreach($this->tags as $i => $tag) {
foreach ($this->tags as $i => $tag) {
if ($tag->getName() == 'event') {
$eventTag = new ReturnTag('event', $tag->getContent(), $tag->getDocBlock(), $tag->getLocation());
$this->type = $eventTag->getType();
Expand Down
4 changes: 2 additions & 2 deletions extensions/apidoc/models/FunctionDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function __construct($reflector = null, $context = null, $config = [])

$this->isReturnByReference = $reflector->isByRef();

foreach($reflector->getArguments() as $arg) {
foreach ($reflector->getArguments() as $arg) {
$arg = new ParamDoc($arg, $context, ['sourceFile' => $this->sourceFile]);
$this->params[$arg->name] = $arg;
}

foreach($this->tags as $i => $tag) {
foreach ($this->tags as $i => $tag) {
if ($tag instanceof ThrowsTag) {
$this->exceptions[$tag->getType()] = $tag->getDescription();
unset($this->tags[$i]);
Expand Down
4 changes: 2 additions & 2 deletions extensions/apidoc/models/InterfaceDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public function __construct($reflector = null, $context = null, $config = [])
return;
}

foreach($reflector->getParentInterfaces() as $interface) {
foreach ($reflector->getParentInterfaces() as $interface) {
$this->parentInterfaces[] = ltrim($interface, '\\');
}

foreach($this->methods as $method) {
foreach ($this->methods as $method) {
$method->isAbstract = true;
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/apidoc/models/PropertyDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct($reflector = null, $context = null, $config = [])
$this->defaultValue = PrettyPrinter::getRepresentationOfValue($reflector->getNode()->default);
}

foreach($this->tags as $tag) {
foreach ($this->tags as $tag) {
if ($tag instanceof VarTag) {
$this->type = $tag->getType();
$this->types = $tag->getTypes();
Expand Down
2 changes: 1 addition & 1 deletion extensions/apidoc/models/TraitDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($reflector = null, $context = null, $config = [])
return;
}

foreach($reflector->getTraits() as $trait) {
foreach ($reflector->getTraits() as $trait) {
$this->traits[] = ltrim($trait, '\\');
}
}
Expand Down
14 changes: 7 additions & 7 deletions extensions/apidoc/models/TypeDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TypeDoc extends BaseDoc
public function findSubject($subjectName)
{
if ($subjectName[0] != '$') {
foreach($this->methods as $name => $method) {
foreach ($this->methods as $name => $method) {
if (rtrim($subjectName, '()') == $name) {
return $method;
}
Expand All @@ -53,7 +53,7 @@ public function findSubject($subjectName)
if ($this->properties === null) {
return null;
}
foreach($this->properties as $name => $property) {
foreach ($this->properties as $name => $property) {
if (ltrim($subjectName, '$') == ltrim($name, '$')) {
return $property;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public function getProtectedMethods()
private function getFilteredMethods($visibility = null, $definedBy = null)
{
$methods = [];
foreach($this->methods as $name => $method) {
foreach ($this->methods as $name => $method) {
if ($visibility !== null && $method->visibility != $visibility) {
continue;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ private function getFilteredProperties($visibility = null, $definedBy = null)
return [];
}
$properties = [];
foreach($this->properties as $name => $property) {
foreach ($this->properties as $name => $property) {
if ($visibility !== null && $property->visibility != $visibility) {
continue;
}
Expand All @@ -167,22 +167,22 @@ public function __construct($reflector = null, $context = null, $config = [])
return;
}

foreach($this->tags as $i => $tag) {
foreach ($this->tags as $i => $tag) {
if ($tag instanceof AuthorTag) {
$this->authors[$tag->getAuthorName()] = $tag->getAuthorEmail();
unset($this->tags[$i]);
}
}

foreach($reflector->getProperties() as $propertyReflector) {
foreach ($reflector->getProperties() as $propertyReflector) {
if ($propertyReflector->getVisibility() != 'private') {
$property = new PropertyDoc($propertyReflector, $context, ['sourceFile' => $this->sourceFile]);
$property->definedBy = $this->name;
$this->properties[$property->name] = $property;
}
}

foreach($reflector->getMethods() as $methodReflector) {
foreach ($reflector->getMethods() as $methodReflector) {
if ($methodReflector->getVisibility() != 'private') {
$method = new MethodDoc($methodReflector, $context, ['sourceFile' => $this->sourceFile]);
$method->definedBy = $this->name;
Expand Down
8 changes: 4 additions & 4 deletions extensions/apidoc/templates/bootstrap/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function renderApi($context, $controller)
$types = array_merge($context->classes, $context->interfaces, $context->traits);

$controller->stdout('generating extension index files...');
foreach($this->extensions as $ext) {
foreach ($this->extensions as $ext) {
$readme = @file_get_contents("https://raw.github.com/yiisoft/yii2-$ext/master/README.md");
$indexFileContent = $this->renderWithLayout($this->indexView, [
'docContext' => $context,
Expand Down Expand Up @@ -151,7 +151,7 @@ public function renderMarkdownFiles($controller)
$done = 0;
$fileData = [];
$headlines = [];
foreach($files as $file) {
foreach ($files as $file) {
$fileData[$file] = file_get_contents($file);
if (basename($file) == 'index.md') {
continue; // to not add index file to nav
Expand All @@ -163,7 +163,7 @@ public function renderMarkdownFiles($controller)
}
}

foreach($fileData as $file => $content) {
foreach ($fileData as $file => $content) {
$output = ApiMarkdown::process($content); // TODO generate links to yiiframework.com by default
$output = $this->fixMarkdownLinks($output);
if ($this->guideLayout !== false) {
Expand Down Expand Up @@ -191,7 +191,7 @@ protected function generateGuideFileName($file)
public function getGuideReferences()
{
$refs = [];
foreach($this->markDownFiles as $file) {
foreach ($this->markDownFiles as $file) {
$refName = 'guide-' . basename($file, '.md');
$refs[$refName] = ['url' => $this->generateGuideFileName($file)];
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/apidoc/templates/bootstrap/SideNavWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function renderItem($item)
$label .= ' ' . Html::tag('b', '', ['class' => 'caret']);
if (is_array($items)) {
if ($active === false) {
foreach($items as $subItem) {
foreach ($items as $subItem) {
if (isset($subItem['active']) && $subItem['active']) {
$active = true;
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/apidoc/templates/bootstrap/layouts/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$types = $this->context->getNavTypes(isset($type) ? $type : null, $types);
ksort($types);
$nav = [];
foreach($types as $i=>$class) {
foreach ($types as $i => $class) {
$namespace = $class->namespace;
if (empty($namespace)) {
$namespace = 'Not namespaced classes';
Expand Down
Loading

0 comments on commit 95ea1c2

Please sign in to comment.