mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
code style. operator IF
This commit is contained in:
@ -120,7 +120,7 @@ needs to be divisible by 10. In the rules you would define: `['attributeName', '
|
||||
Then, your own method could look like this:
|
||||
```php
|
||||
public function myValidationMethod($attribute) {
|
||||
if(($this->$attribute % 10) != 0) {
|
||||
if (($this->$attribute % 10) != 0) {
|
||||
$this->addError($attribute, 'cannot divide value by 10');
|
||||
}
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ if ($event === null) {
|
||||
}
|
||||
|
||||
// the following is NOT allowed:
|
||||
if(!$model && null === $event)
|
||||
if (!$model && null === $event)
|
||||
throw new Exception('test');
|
||||
```
|
||||
|
||||
|
@ -106,10 +106,11 @@ class BaseDoc extends Object
|
||||
|
||||
public function getSourceUrl($baseUrl, $line=null)
|
||||
{
|
||||
if($line === null)
|
||||
if ($line === null) {
|
||||
return $baseUrl . $this->sourcePath;
|
||||
else
|
||||
} else {
|
||||
return $baseUrl . $this->sourcePath . '#' . $line;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSourceCode()
|
||||
|
@ -235,7 +235,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
|
||||
$parents = [];
|
||||
$parents[] = $this->typeLink($class);
|
||||
while ($class->parentClass !== null) {
|
||||
if(isset($this->context->classes[$class->parentClass])) {
|
||||
if (isset($this->context->classes[$class->parentClass])) {
|
||||
$class = $this->context->classes[$class->parentClass];
|
||||
$parents[] = $this->typeLink($class);
|
||||
} else {
|
||||
@ -255,7 +255,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
|
||||
$interfaces = [];
|
||||
sort($names, SORT_STRING);
|
||||
foreach($names as $interface) {
|
||||
if(isset($this->context->interfaces[$interface])) {
|
||||
if (isset($this->context->interfaces[$interface])) {
|
||||
$interfaces[] = $this->typeLink($this->context->interfaces[$interface]);
|
||||
} else {
|
||||
$interfaces[] = $interface; // TODO link to php.net
|
||||
@ -273,7 +273,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
|
||||
$traits = [];
|
||||
sort($names, SORT_STRING);
|
||||
foreach($names as $trait) {
|
||||
if(isset($this->context->traits[$trait])) {
|
||||
if (isset($this->context->traits[$trait])) {
|
||||
$traits[] = $this->typeLink($this->context->traits[$trait]);
|
||||
} else {
|
||||
$traits[] = $trait; // TODO link to php.net
|
||||
@ -291,7 +291,7 @@ abstract class Renderer extends BaseRenderer implements ViewContextInterface
|
||||
$classes = [];
|
||||
sort($names, SORT_STRING);
|
||||
foreach($names as $class) {
|
||||
if(isset($this->context->classes[$class])) {
|
||||
if (isset($this->context->classes[$class])) {
|
||||
$classes[] = $this->typeLink($this->context->classes[$class]);
|
||||
} else {
|
||||
$classes[] = $class; // TODO link to php.net
|
||||
|
@ -21,7 +21,7 @@ ArrayHelper::multisort($events, 'name');
|
||||
<?= $event->name ?>
|
||||
<span class="detailHeaderTag small">
|
||||
event
|
||||
<?php if(!empty($event->since)): ?>
|
||||
<?php if (!empty($event->since)): ?>
|
||||
(available since version <?= $event->since ?>)
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
|
@ -35,7 +35,7 @@ ArrayHelper::multisort($events, 'name');
|
||||
<td><?= $this->context->typeLink($event->types) ?></td>
|
||||
<td>
|
||||
<?= ApiMarkdown::process($event->shortDescription, $event->definedBy, true) ?>
|
||||
<?php if(!empty($event->since)): ?>
|
||||
<?php if (!empty($event->since)): ?>
|
||||
(available since version <?= $event->since ?>)
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
|
@ -35,7 +35,7 @@ ArrayHelper::multisort($methods, 'name');
|
||||
<tr><td colspan="3">
|
||||
<div class="signature2"><?= $this->context->renderMethodSignature($method) ?></div>
|
||||
</td></tr>
|
||||
<?php if(!empty($method->params) || !empty($method->return) || !empty($method->exceptions)): ?>
|
||||
<?php if (!empty($method->params) || !empty($method->return) || !empty($method->exceptions)): ?>
|
||||
<?php foreach($method->params as $param): ?>
|
||||
<tr>
|
||||
<td class="paramNameCol"><?= $param->name ?></td>
|
||||
@ -43,7 +43,7 @@ ArrayHelper::multisort($methods, 'name');
|
||||
<td class="paramDescCol"><?= ApiMarkdown::process($param->description, $type) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php if(!empty($method->return)): ?>
|
||||
<?php if (!empty($method->return)): ?>
|
||||
<tr>
|
||||
<td class="paramNameCol"><?= 'return'; ?></td>
|
||||
<td class="paramTypeCol"><?= $this->context->typeLink($method->returnTypes); ?></td>
|
||||
|
@ -34,7 +34,7 @@ if ($protected && count($type->getProtectedMethods()) == 0 || !$protected && cou
|
||||
$methods = $type->methods;
|
||||
ArrayHelper::multisort($methods, 'name');
|
||||
foreach($methods as $method): ?>
|
||||
<?php if($protected && $method->visibility == 'protected' || !$protected && $method->visibility != 'protected'): ?>
|
||||
<?php if ($protected && $method->visibility == 'protected' || !$protected && $method->visibility != 'protected'): ?>
|
||||
<tr<?= $method->definedBy != $type->name ? ' class="inherited"' : '' ?> id="<?= $method->name ?>()">
|
||||
<td><?= $this->context->subjectLink($method, $method->name.'()') ?></td>
|
||||
<td><?= ApiMarkdown::process($method->shortDescription, $method->definedBy, true) ?></td>
|
||||
|
@ -24,10 +24,10 @@ ArrayHelper::multisort($properties, 'name');
|
||||
<?= $property->name ?>
|
||||
<span class="detailHeaderTag small">
|
||||
<?= $property->visibility ?>
|
||||
<?php if($property->getIsReadOnly()) echo ' <em>read-only</em> '; ?>
|
||||
<?php if($property->getIsWriteOnly()) echo ' <em>write-only</em> '; ?>
|
||||
<?php if ($property->getIsReadOnly()) echo ' <em>read-only</em> '; ?>
|
||||
<?php if ($property->getIsWriteOnly()) echo ' <em>write-only</em> '; ?>
|
||||
property
|
||||
<?php if(!empty($property->since)): ?>
|
||||
<?php if (!empty($property->since)): ?>
|
||||
(available since version <?= $property->since ?>)
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
|
@ -34,7 +34,7 @@ if ($protected && count($type->getProtectedProperties()) == 0 || !$protected &&
|
||||
$properties = $type->properties;
|
||||
ArrayHelper::multisort($properties, 'name');
|
||||
foreach($properties as $property): ?>
|
||||
<?php if($protected && $property->visibility == 'protected' || !$protected && $property->visibility != 'protected'): ?>
|
||||
<?php if ($protected && $property->visibility == 'protected' || !$protected && $property->visibility != 'protected'): ?>
|
||||
<tr<?= $property->definedBy != $type->name ? ' class="inherited"' : '' ?> id="<?= $property->name ?>">
|
||||
<td><?= $this->context->subjectLink($property) ?></td>
|
||||
<td><?= $this->context->typeLink($property->types) ?></td>
|
||||
|
@ -30,16 +30,16 @@ $renderer = $this->context;
|
||||
?></h1>
|
||||
<div id="nav">
|
||||
<a href="index.html">All Classes</a>
|
||||
<?php if(!($type instanceof InterfaceDoc) && !empty($type->properties)): ?>
|
||||
<?php if (!($type instanceof InterfaceDoc) && !empty($type->properties)): ?>
|
||||
| <a href="#properties">Properties</a>
|
||||
<?php endif; ?>
|
||||
<?php if(!empty($type->methods)): ?>
|
||||
<?php if (!empty($type->methods)): ?>
|
||||
| <a href="#methods">Methods</a>
|
||||
<?php endif; ?>
|
||||
<?php if($type instanceof ClassDoc && !empty($type->events)): ?>
|
||||
<?php if ($type instanceof ClassDoc && !empty($type->events)): ?>
|
||||
| <a href="#events">Events</a>
|
||||
<?php endif; ?>
|
||||
<?php if($type instanceof ClassDoc && !empty($type->constants)): ?>
|
||||
<?php if ($type instanceof ClassDoc && !empty($type->constants)): ?>
|
||||
| <a href="#constants">Constants</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@ -55,10 +55,10 @@ $renderer = $this->context;
|
||||
<?php if ($type instanceof ClassDoc && !empty($type->interfaces)): ?>
|
||||
<tr><th>Implements</th><td><?= $renderer->renderInterfaces($type->interfaces) ?></td></tr>
|
||||
<?php endif; ?>
|
||||
<?php if(!($type instanceof InterfaceDoc) && !empty($type->traits)): ?>
|
||||
<?php if (!($type instanceof InterfaceDoc) && !empty($type->traits)): ?>
|
||||
<tr><th>Uses Traits</th><td><?= $renderer->renderTraits($type->traits) ?></td></tr>
|
||||
<?php endif; ?>
|
||||
<?php if($type instanceof ClassDoc && !empty($type->subclasses)): ?>
|
||||
<?php if ($type instanceof ClassDoc && !empty($type->subclasses)): ?>
|
||||
<tr><th>Subclasses</th><td><?= $renderer->renderClasses($type->subclasses) ?></td></tr>
|
||||
<?php endif; ?>
|
||||
<?php if ($type instanceof InterfaceDoc && !empty($type->implementedBy)): ?>
|
||||
@ -67,7 +67,7 @@ $renderer = $this->context;
|
||||
<?php if ($type instanceof TraitDoc && !empty($type->usedBy)): ?>
|
||||
<tr><th>Implemented by</th><td><?= $renderer->renderClasses($type->usedBy) ?></td></tr>
|
||||
<?php endif; ?>
|
||||
<?php if(!empty($type->since)): ?>
|
||||
<?php if (!empty($type->since)): ?>
|
||||
<tr><th>Available since version</th><td><?= $type->since ?></td></tr>
|
||||
<?php endif; ?>
|
||||
<tr>
|
||||
@ -97,6 +97,6 @@ $renderer = $this->context;
|
||||
|
||||
<?= $this->render('@yii/apidoc/templates/html/views/propertyDetails', ['type' => $type]) ?>
|
||||
<?= $this->render('@yii/apidoc/templates/html/views/methodDetails', ['type' => $type]) ?>
|
||||
<?php if($type instanceof ClassDoc): ?>
|
||||
<?php if ($type instanceof ClassDoc): ?>
|
||||
<?= $this->render('@yii/apidoc/templates/html/views/eventDetails', ['type' => $type]) ?>
|
||||
<?php endif; ?>
|
||||
|
@ -175,7 +175,7 @@ class OAuth1 extends BaseOAuth
|
||||
}
|
||||
case 'POST': {
|
||||
$curlOptions[CURLOPT_POST] = true;
|
||||
if (!empty($params)){
|
||||
if (!empty($params)) {
|
||||
$curlOptions[CURLOPT_POSTFIELDS] = $params;
|
||||
}
|
||||
$authorizationHeader = $this->composeAuthorizationHeader($params);
|
||||
|
@ -243,10 +243,10 @@ class OpenId extends BaseClient implements ClientInterface
|
||||
|
||||
if ($this->verifyPeer !== null) {
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
|
||||
if($this->capath) {
|
||||
if ($this->capath) {
|
||||
curl_setopt($curl, CURLOPT_CAPATH, $this->capath);
|
||||
}
|
||||
if($this->cainfo) {
|
||||
if ($this->cainfo) {
|
||||
curl_setopt($curl, CURLOPT_CAINFO, $this->cainfo);
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ HTML;
|
||||
}
|
||||
}
|
||||
// Added lines only on the right side
|
||||
else if ($change['tag'] === 'insert') {
|
||||
elseif ($change['tag'] === 'insert') {
|
||||
foreach ($change['changed']['lines'] as $no => $line) {
|
||||
$toLine = $change['changed']['offset'] + $no + 1;
|
||||
$html .= <<<HTML
|
||||
@ -86,7 +86,7 @@ HTML;
|
||||
}
|
||||
}
|
||||
// Show deleted lines only on the left side
|
||||
else if ($change['tag'] === 'delete') {
|
||||
elseif ($change['tag'] === 'delete') {
|
||||
foreach ($change['base']['lines'] as $no => $line) {
|
||||
$fromLine = $change['base']['offset'] + $no + 1;
|
||||
$html .= <<<HTML
|
||||
@ -99,7 +99,7 @@ HTML;
|
||||
}
|
||||
}
|
||||
// Show modified lines on both sides
|
||||
else if ($change['tag'] === 'replace') {
|
||||
elseif ($change['tag'] === 'replace') {
|
||||
foreach ($change['base']['lines'] as $no => $line) {
|
||||
$fromLine = $change['base']['offset'] + $no + 1;
|
||||
$html .= <<<HTML
|
||||
|
@ -78,7 +78,7 @@ class Cache extends \yii\caching\Cache
|
||||
parent::init();
|
||||
if (is_string($this->redis)) {
|
||||
$this->redis = Yii::$app->getComponent($this->redis);
|
||||
} else if (is_array($this->redis)) {
|
||||
} elseif (is_array($this->redis)) {
|
||||
if (!isset($this->redis['class'])) {
|
||||
$this->redis['class'] = Connection::className();
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ class Session extends \yii\web\Session
|
||||
{
|
||||
if (is_string($this->redis)) {
|
||||
$this->redis = Yii::$app->getComponent($this->redis);
|
||||
} else if (is_array($this->redis)) {
|
||||
} elseif (is_array($this->redis)) {
|
||||
if (!isset($this->redis['class'])) {
|
||||
$this->redis['class'] = Connection::className();
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ class MessageController extends Controller
|
||||
{
|
||||
echo "Saving messages to $fileName...";
|
||||
if (is_file($fileName)) {
|
||||
if($format === 'po'){
|
||||
if ($format === 'po') {
|
||||
$translated = file_get_contents($fileName);
|
||||
preg_match_all('/(?<=msgid ").*(?="\n(#*)msgstr)/', $translated, $keys);
|
||||
preg_match_all('/(?<=msgstr ").*(?="\n\n)/', $translated, $values);
|
||||
@ -285,7 +285,7 @@ class MessageController extends Controller
|
||||
$merged = [];
|
||||
$untranslated = [];
|
||||
foreach ($messages as $message) {
|
||||
if($format === 'po'){
|
||||
if ($format === 'po') {
|
||||
$message = preg_replace('/\"/', '\"', $message);
|
||||
}
|
||||
if (array_key_exists($message, $translated) && strlen($translated[$message]) > 0) {
|
||||
@ -317,7 +317,7 @@ class MessageController extends Controller
|
||||
if (false === $overwrite) {
|
||||
$fileName .= '.merged';
|
||||
}
|
||||
if ($format === 'po'){
|
||||
if ($format === 'po') {
|
||||
$output = '';
|
||||
foreach ($merged as $k => $v){
|
||||
$k = preg_replace('/(\")|(\\\")/', "\\\"", $k);
|
||||
|
@ -397,7 +397,7 @@ class BaseFileHelper
|
||||
if ($pattern === $baseName) {
|
||||
return true;
|
||||
}
|
||||
} else if ($flags & self::PATTERN_ENDSWITH) {
|
||||
} elseif ($flags & self::PATTERN_ENDSWITH) {
|
||||
/* "*literal" matching against "fooliteral" */
|
||||
$n = StringHelper::byteLength($pattern);
|
||||
if (StringHelper::byteSubstr($pattern, 1, $n) === StringHelper::byteSubstr($baseName, -$n, $n)) {
|
||||
|
@ -86,7 +86,7 @@ class BaseMarkdown
|
||||
/** @var \cebe\markdown\Markdown $parser */
|
||||
if (!isset(static::$flavors[$flavor])) {
|
||||
throw new InvalidParamException("Markdown flavor '$flavor' is not defined.'");
|
||||
} elseif(!is_object($config = static::$flavors[$flavor])) {
|
||||
} elseif (!is_object($config = static::$flavors[$flavor])) {
|
||||
$parser = Yii::createObject($config);
|
||||
if (is_array($config)) {
|
||||
foreach ($config as $name => $value) {
|
||||
|
@ -70,9 +70,9 @@ class GettextMessageSource extends MessageSource
|
||||
|
||||
if ($messages === null && $fallbackMessages === null && $fallbackLanguage != $this->sourceLanguage) {
|
||||
Yii::error("The message file for category '$category' does not exist: $messageFile Fallback file does not exist as well: $fallbackMessageFile", __METHOD__);
|
||||
} else if (empty($messages)) {
|
||||
} elseif (empty($messages)) {
|
||||
return $fallbackMessages;
|
||||
} else if (!empty($fallbackMessages)) {
|
||||
} elseif (!empty($fallbackMessages)) {
|
||||
foreach ($fallbackMessages as $key => $value) {
|
||||
if (!empty($value) && empty($messages[$key])) {
|
||||
$messages[$key] = $fallbackMessages[$key];
|
||||
|
@ -73,9 +73,9 @@ class PhpMessageSource extends MessageSource
|
||||
|
||||
if ($messages === null && $fallbackMessages === null && $fallbackLanguage != $this->sourceLanguage) {
|
||||
Yii::error("The message file for category '$category' does not exist: $messageFile Fallback file does not exist as well: $fallbackMessageFile", __METHOD__);
|
||||
} else if (empty($messages)) {
|
||||
} elseif (empty($messages)) {
|
||||
return $fallbackMessages;
|
||||
} else if (!empty($fallbackMessages)) {
|
||||
} elseif (!empty($fallbackMessages)) {
|
||||
foreach ($fallbackMessages as $key => $value) {
|
||||
if (!empty($value) && empty($messages[$key])) {
|
||||
$messages[$key] = $fallbackMessages[$key];
|
||||
|
@ -27,7 +27,7 @@ class ElasticSearchTestCase extends TestCase
|
||||
if (strpos($host, ':')===false) {
|
||||
$host .= ':9200';
|
||||
}
|
||||
if(!@stream_socket_client($host, $errorNumber, $errorDescription, 0.5)) {
|
||||
if (!@stream_socket_client($host, $errorNumber, $errorDescription, 0.5)) {
|
||||
$this->markTestSkipped('No elasticsearch server running at ' . $params['dsn'] . ' : ' . $errorNumber . ' - ' . $errorDescription);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ class RedisCacheTest extends CacheTestCase
|
||||
$this->markTestSkipped('No redis server connection configured.');
|
||||
}
|
||||
$connection = new Connection($params);
|
||||
if(!@stream_socket_client($connection->hostname . ':' . $connection->port, $errorNumber, $errorDescription, 0.5)) {
|
||||
if (!@stream_socket_client($connection->hostname . ':' . $connection->port, $errorNumber, $errorDescription, 0.5)) {
|
||||
$this->markTestSkipped('No redis server running at ' . $connection->hostname . ':' . $connection->port . ' : ' . $errorNumber . ' - ' . $errorDescription);
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ abstract class RedisTestCase extends TestCase
|
||||
$this->markTestSkipped('No redis server connection configured.');
|
||||
}
|
||||
$connection = new Connection($params);
|
||||
if(!@stream_socket_client($connection->hostname . ':' . $connection->port, $errorNumber, $errorDescription, 0.5)) {
|
||||
if (!@stream_socket_client($connection->hostname . ':' . $connection->port, $errorNumber, $errorDescription, 0.5)) {
|
||||
$this->markTestSkipped('No redis server running at ' . $connection->hostname . ':' . $connection->port . ' : ' . $errorNumber . ' - ' . $errorDescription);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user