Skip to content

Commit 15f36ce

Browse files
committed
refactoring
1 parent a54d3c0 commit 15f36ce

File tree

9 files changed

+69
-16
lines changed

9 files changed

+69
-16
lines changed

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"yiisoft/yii2": ">=2.0.6",
99
"symfony/filesystem": "^3.1",
1010
"symfony/finder": "^3.1",
11-
"voskobovich/yii2-many-many-behavior": ">=3.2.0"
11+
"voskobovich/yii2-linker-behavior": "dev-master"
1212
},
1313
"autoload": {
1414
"psr-4": {
@@ -17,5 +17,8 @@
1717
},
1818
"extra": {
1919
"bootstrap":"nullref\\core\\Bootstrap"
20+
},
21+
"require-dev": {
22+
"yiisoft/yii2-gii": "^2.0@dev"
2023
}
2124
}

src/Bootstrap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function bootstrap($app)
4141
];
4242
}
4343
if (YII_ENV_DEV && class_exists('yii\gii\Module')) {
44-
Event::on(Gii::className(), Gii::EVENT_BEFORE_ACTION, function (Event $event) {
44+
Event::on(Gii::class, Gii::EVENT_BEFORE_ACTION, function (Event $event) {
4545
/** @var Gii $gii */
4646
$gii = $event->sender;
4747
$gii->generators['relation-migration'] = [

src/behaviors/ManyHasManyRelation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace nullref\core\behaviors;
44

55
use nullref\core\traits\EntityManageble;
6-
use voskobovich\behaviors\ManyToManyBehavior;
6+
use voskobovich\linker\LinkerBehavior;
77
use yii\db\ActiveRecord;
88

99
/**
@@ -47,7 +47,7 @@ public function getTableName()
4747
public function attach($owner)
4848
{
4949
$owner->attachBehavior($this->getRelationName(), [
50-
'class' => ManyToManyBehavior::className(),
50+
'class' => LinkerBehavior::class,
5151
'relations' => [
5252
$this->getAttributeName() => $this->getRelationName(),
5353
],

src/components/EntityManager.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getDeleteField()
7878
public static function getConfig($namespace, $modelName, $config = [])
7979
{
8080
$default = [
81-
'class' => static::className(),
81+
'class' => get_called_class(),
8282
'model' => $namespace . $modelName,
8383
'query' => $namespace . $modelName . 'Query',
8484
'searchModel' => $namespace . $modelName . 'Search',
@@ -88,7 +88,10 @@ public static function getConfig($namespace, $modelName, $config = [])
8888

8989
/**
9090
* @param Model $model
91-
* @return void
91+
* @return mixed|void
92+
* @throws \Exception
93+
* @throws \Throwable
94+
* @throws \yii\db\StaleObjectException
9295
*/
9396
public function delete($model)
9497
{
@@ -175,8 +178,7 @@ public function createModel()
175178
}
176179

177180
/**
178-
* @return object
179-
* @throws \yii\base\InvalidConfigException
181+
* @return ActiveQuery
180182
*/
181183
public function createQuery()
182184
{
@@ -198,7 +200,8 @@ public function createQuery()
198200
}
199201

200202
/**
201-
* @return mixed
203+
* @return object
204+
* @throws InvalidConfigException
202205
*/
203206
public function createSearchModel()
204207
{

src/components/LanguageManager.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class LanguageManager extends Component implements ILanguageManager
5050

5151
/**
5252
* Try to read language from session and cookies
53+
*
54+
* @throws \yii\base\InvalidConfigException
5355
*/
5456
public function init()
5557
{
@@ -68,7 +70,7 @@ public function init()
6870
$selectedLanguage = null;
6971
foreach ($this->languages as $config) {
7072
if (is_array($config) && !isset($config['class'])) {
71-
$config['class'] = Language::className();
73+
$config['class'] = Language::class;
7274
}
7375
/** @var ILanguage $language */
7476
$language = \Yii::createObject($config);

src/components/ModuleInstaller.php

+23-1
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,30 @@ abstract class ModuleInstaller extends Component
2727
public $runModuleMigrations = false;
2828
public $updateConfig = true;
2929

30+
/**
31+
* @throws \yii\base\InvalidConfigException
32+
* @throws \yii\base\NotSupportedException
33+
*/
3034
public function init()
3135
{
3236
parent::init();
33-
$this->db = Instance::ensure($this->db, Connection::className());
37+
$this->db = Instance::ensure($this->db, Connection::class);
3438
$this->db->getSchema()->refresh();
3539
}
3640

41+
/**
42+
* @param $action
43+
* @return bool
44+
*/
3745
public function hasChange($action)
3846
{
3947
return ($this->getChange($action) !== null);
4048
}
4149

50+
/**
51+
* @param $action
52+
* @return mixed|null
53+
*/
4254
public function getChange($action)
4355
{
4456
$changes = $this->getChanges();
@@ -50,6 +62,9 @@ public function getChange($action)
5062
return null;
5163
}
5264

65+
/**
66+
* @return array|mixed
67+
*/
5368
public function getChanges()
5469
{
5570
$array = [];
@@ -67,8 +82,14 @@ protected function getChangesPath()
6782
return \Yii::getAlias('@app/config/changes.php');
6883
}
6984

85+
/**
86+
* @return mixed
87+
*/
7088
public abstract function getModuleId();
7189

90+
/**
91+
*
92+
*/
7293
public function install()
7394
{
7495
$this->stdout(' Module "' . $this->getModuleId() . '" installing: ' . PHP_EOL, Console::FG_BLUE, Console::NEGATIVE, Console::BOLD);
@@ -221,6 +242,7 @@ protected function removeFromConfig()
221242
*
222243
* @param $alias
223244
* @param bool $override
245+
* @throws \yii\base\Exception
224246
*/
225247
protected function createFile($alias, $override = true)
226248
{

src/console/MigrateController.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function beforeAction($action)
7070
*/
7171
public function getMigrationNamespace($module)
7272
{
73-
$reflection = new \ReflectionClass($module->className());
73+
$reflection = new \ReflectionClass($module->class);
7474
$baseNamespace = $reflection->getNamespaceName() . '\\migrations';
7575
$namespaces = [$baseNamespace];
7676

@@ -95,6 +95,7 @@ public function getMigrationNamespace($module)
9595

9696
/**
9797
* @param string $name
98+
* @throws \yii\console\Exception
9899
*/
99100
public function actionCreate($name)
100101
{
@@ -126,8 +127,10 @@ protected function nameHasNamespace($name)
126127

127128
/**
128129
* Return migrations only with namespace
129-
* @param int $limit
130+
*
131+
* @param $limit
130132
* @return array
133+
* @throws \yii\db\Exception
131134
*/
132135
protected function getMigrationHistory($limit)
133136
{

src/console/ModuleController.php

+22-2
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,31 @@ class ModuleController extends Controller
1717
{
1818
public $db = 'db';
1919

20+
/**
21+
*
22+
*/
2023
public function actionIndex()
2124
{
2225
$this->run('/help', ['module']);
2326
}
2427

2528
/**
2629
* Run installation
30+
*
2731
* @param $name
32+
* @throws \yii\base\InvalidConfigException
2833
*/
2934
public function actionInstall($name)
3035
{
3136
$this->runInstallerCommand($name, 'install', 'Module module was installed successfully.');
3237
}
3338

39+
/**
40+
* @param $name
41+
* @param $method
42+
* @param string $message
43+
* @throws \yii\base\InvalidConfigException
44+
*/
3445
protected function runInstallerCommand($name, $method, $message = '')
3546
{
3647
if ($this->moduleExists($name)) {
@@ -90,6 +101,9 @@ protected function getInstaller($name)
90101
}
91102
}
92103

104+
/**
105+
*
106+
*/
93107
public function actionMigrate()
94108
{
95109
$changes = $this->getChanges();
@@ -99,16 +113,21 @@ public function actionMigrate()
99113
Console::output('Migrate successfully.');
100114
}
101115

116+
/**
117+
* @return array|mixed
118+
* @throws \yii\base\InvalidConfigException
119+
*/
102120
protected function getChanges()
103121
{
104122
/** @var Installer $installer */
105-
$installer = \Yii::createObject(Installer::className(), ['db' => $this->db]);
123+
$installer = \Yii::createObject(Installer::class, ['db' => $this->db]);
106124

107125
return $installer->getChanges();
108126
}
109127

110128
/**
111129
* @param $name
130+
* @throws \yii\base\InvalidConfigException
112131
*/
113132
public function actionUninstall($name)
114133
{
@@ -130,6 +149,7 @@ public function actionUninstall($name)
130149

131150
/**
132151
* @param $name
152+
* @throws \yii\base\InvalidConfigException
133153
*/
134154
public function actionReinstall($name)
135155
{
@@ -146,7 +166,7 @@ public function actionBindModels($modelName1, $modelName2)
146166
$model2 = new $modelName2();
147167

148168
if ($this->confirm('Generate migration?')) {
149-
169+
//@TODO
150170
}
151171
}
152172
}

src/generators/migration/Generator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function validateModelClass($attribute)
8080
$class = $this->{$attribute};
8181
try {
8282
$reflection = new \ReflectionClass($class);
83-
if (!$reflection->isSubclassOf(ActiveRecord::className())) {
83+
if (!$reflection->isSubclassOf(ActiveRecord::class)) {
8484
$this->addError($attribute, 'Class must be model');
8585
}
8686
} catch (\Exception $e) {

0 commit comments

Comments
 (0)