AuthDb::doOperation()   F
last analyzed

Complexity

Conditions 26
Paths 273

Size

Total Lines 125
Code Lines 89

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 3 Features 4
Metric Value
c 6
b 3
f 4
dl 0
loc 125
rs 3.5303
cc 26
eloc 89
nc 273
nop 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * AuthDb
4
 *
5
 * BASIC認証のためのファンクション群(AuthProvider)
6
 *
7
 * @package           risoluto
8
 * @author            Risoluto Developers
9
 * @license           http://opensource.org/licenses/bsd-license.php new BSD license
10
 * @copyright     (C) 2008-2015 Risoluto Developers / All Rights Reserved.
11
 */
12
13
//------------------------------------------------------//
14
// 名前空間の定義
15
//------------------------------------------------------//
16
namespace Risoluto;
17
18
//------------------------------------------------------//
19
// クラス定義
20
//------------------------------------------------------//
21
class AuthDb implements \Risoluto\AuthProviderInterface
22
{
23
    //------------------------------------------------------//
24
    // クラスメソッド定義
25
    //------------------------------------------------------//
26
    /**
27
     * getSqlInitUserTbl()
28
     *
29
     * ユーザ情報テーブル初期化のためのSQLを生成する
30
     *
31
     * @access    private
32
     *
33
     * @param     string $tablename ユーザ情報テーブル名
34
     *
35
     * @return    SQL
36
     */
37
    private function getSqlInitUserTbl( $tablename )
38
    {
39
        $sql = <<<END_OF_SQL
40
DROP TABLE IF EXISTS $tablename;
41
CREATE TABLE IF NOT EXISTS $tablename
42
(
43
      `created_at`  DATETIME     NOT NULL
44
    , `created_by`  VARCHAR(255) NOT NULL
45
    , `modified_at` DATETIME     NOT NULL
46
    , `modified_by` VARCHAR(255) NOT NULL
47
    , `no`          INT UNSIGNED NOT NULL AUTO_INCREMENT
48
    , `userid`      VARCHAR(255) NOT NULL UNIQUE
49
    , `username`    VARCHAR(255) NOT NULL
50
    , `password`    VARCHAR(255) NOT NULL
51
    , `groupno`     INT UNSIGNED NOT NULL
52
    , `status`      TINYINT(1)   NOT NULL DEFAULT 1
53
    , PRIMARY KEY  (
54
                     `no`
55
                   )
56
) ENGINE=InnoDB CHARACTER SET utf8;
57
58
INSERT INTO $tablename(
59
      `created_at`
60
    , `created_by`
61
    , `modified_at`
62
    , `modified_by`
63
    , `no`
64
    , `userid`
65
    , `username`
66
    , `password`
67
    , `groupno`
68
    , `status`
69
) VALUES (
70
      now()
71
    , 'Risoluto AuthDb Init'
72
    , now()
73
    , 'Risoluto AuthDb Init'
74
    , 1
75
    , 'admin'
76
    , 'Risoluto Admin'
77
    , '$2y$10\$Z.74cnnXxRHjlUfDaVA/5e9wCTG7DzZ1fRFJQPwHjQYdVInSB0eKO'
78
    , 1
79
    , 1
80
);
81
END_OF_SQL;
82
83
        return $sql;
84
    }
85
86
    /**
87
     * getSqlInitGroupTbl()
88
     *
89
     * グループ情報テーブル初期化のためのSQLを生成する
90
     *
91
     * @access    private
92
     *
93
     * @param     string $tablename グループ情報テーブル名
94
     *
95
     * @return    SQL
96
     */
97
    private function getSqlInitGroupTbl( $tablename )
98
    {
99
        $sql = <<<END_OF_SQL
100
DROP TABLE IF EXISTS $tablename;
101
CREATE TABLE IF NOT EXISTS $tablename
102
(
103
      `created_at`  DATETIME     NOT NULL
104
    , `created_by`  VARCHAR(255) NOT NULL
105
    , `modified_at` DATETIME     NOT NULL
106
    , `modified_by` VARCHAR(255) NOT NULL
107
    , `no`          INT UNSIGNED NOT NULL AUTO_INCREMENT
108
    , `groupid`     VARCHAR(255) NOT NULL UNIQUE
109
    , `groupname`   VARCHAR(255) NOT NULL
110
    , `status`      TINYINT(1)   NOT NULL DEFAULT 1
111
    , PRIMARY KEY  (
112
                     `no`
113
                   )
114
) ENGINE=InnoDB CHARACTER SET utf8;
115
116
INSERT INTO $tablename (
117
      `created_at`
118
    , `created_by`
119
    , `modified_at`
120
    , `modified_by`
121
    , `no`
122
    , `groupid`
123
    , `groupname`
124
    , `status`
125
) VALUES (
126
      now()
127
    , 'Risoluto AuthDb Init'
128
    , now()
129
    , 'Risoluto AuthDb Init'
130
    , 1
131
    , 'admin'
132
    , 'Risoluto Admin Group'
133
    , 1
134
);
135
END_OF_SQL;
136
137
        return $sql;
138
    }
139
140
    /**
141
     * getSqlAddUser()
142
     *
143
     * ユーザ追加のためのSQLを生成する
144
     *
145
     * @access    private
146
     *
147
     * @param     string $tablename ユーザ情報テーブル名
148
     *
149
     * @return    SQL
150
     */
151
    private function getSqlAddUser( $tablename )
152
    {
153
        $sql = <<<END_OF_SQL
154
INSERT INTO $tablename (
155
      `created_at`
156
    , `created_by`
157
    , `modified_at`
158
    , `modified_by`
159
    , `userid`
160
    , `username`
161
    , `password`
162
    , `groupno`
163
    , `status`
164
) values (
165
      now()
166
    , :by_who
167
    , now()
168
    , :by_who
169
    , :userid
170
    , :username
171
    , :password
172
    , :groupno
173
    , :status
174
);
175
END_OF_SQL;
176
177
        return $sql;
178
    }
179
180
181
    /**
182
     * getSqlAddGroup()
183
     *
184
     * グループ追加のためのSQLを生成する
185
     *
186
     * @access    private
187
     *
188
     * @param     string $tablename ユーザ情報テーブル名
189
     *
190
     * @return    SQL
191
     */
192
    private function getSqlAddGroup( $tablename )
193
    {
194
        $sql = <<<END_OF_SQL
195
INSERT INTO $tablename (
196
      `created_at`
197
    , `created_by`
198
    , `modified_at`
199
    , `modified_by`
200
    , `groupid`
201
    , `groupname`
202
    , `status`
203
) values (
204
      now()
205
    , :by_who
206
    , now()
207
    , :by_who
208
    , :groupid
209
    , :groupname
210
    , :status
211
);
212
END_OF_SQL;
213
214
        return $sql;
215
    }
216
217
    /**
218
     * getSqlModUser()
219
     *
220
     * ユーザ情報変更のためのSQLを生成する
221
     *
222
     * @access    private
223
     *
224
     * @param     string $tablename ユーザ情報テーブル名
225
     *
226
     * @return    SQL
227
     */
228
    private function getSqlModUser( $tablename )
229
    {
230
        $sql = <<<END_OF_SQL
231
UPDATE $tablename
232
   SET `modified_at` = now()
233
     , `modified_by` = :by_who
234
     , `username`    = :username
235
     , `password`    = :password
236
     , `groupno`     = :groupno
237
     , `status`      = :status
238
 WHERE `userid`      = :userid;
239
END_OF_SQL;
240
241
        return $sql;
242
    }
243
244
    /**
245
     * getSqlModGroup()
246
     *
247
     * グループ情報変更のためのSQLを生成する
248
     *
249
     * @access    private
250
     *
251
     * @param     string $tablename ユーザ情報テーブル名
252
     *
253
     * @return    初期化用SQL
254
     */
255
    private function getSqlModGroup( $tablename )
256
    {
257
        $sql = <<<END_OF_SQL
258
UPDATE $tablename
259
   SET `modified_at` = now()
260
     , `modified_by` = :by_who
261
     , `groupname`   = :groupname
262
     , `status`      = :status
263
 WHERE `groupid`     = :groupid;
264
END_OF_SQL;
265
266
        return $sql;
267
    }
268
269
    /**
270
     * getSqlModUserByNo()
271
     *
272
     * ユーザ情報変更のためのSQLを生成する(Noでの更新用)
273
     *
274
     * @access    private
275
     *
276
     * @param     string $tablename ユーザ情報テーブル名
277
     *
278
     * @return    SQL
279
     */
280
    private function getSqlModUserByNo( $tablename )
281
    {
282
        $sql = <<<END_OF_SQL
283
UPDATE $tablename
284
   SET `modified_at` = now()
285
     , `modified_by` = :by_who
286
     , `userid`      = :userid
287
     , `username`    = :username
288
     , `password`    = :password
289
     , `groupno`     = :groupno
290
     , `status`      = :status
291
 WHERE `no`          = :no;
292
END_OF_SQL;
293
294
        return $sql;
295
    }
296
297
    /**
298
     * getSqlModGroupByNo()
299
     *
300
     * グループ情報変更のためのSQLを生成する(Noでの更新用)
301
     *
302
     * @access    private
303
     *
304
     * @param     string $tablename ユーザ情報テーブル名
305
     *
306
     * @return    初期化用SQL
307
     */
308
    private function getSqlModGroupByNo( $tablename )
309
    {
310
        $sql = <<<END_OF_SQL
311
UPDATE $tablename
312
   SET `modified_at` = now()
313
     , `modified_by` = :by_who
314
     , `groupid`     = :groupid
315
     , `groupname`   = :groupname
316
     , `status`      = :status
317
 WHERE `no`          = :no;
318
END_OF_SQL;
319
320
        return $sql;
321
    }
322
323
    /**
324
     * getSqlDelUser()
325
     *
326
     * ユーザ情報削除のためのSQLを生成する
327
     *
328
     * @access    private
329
     *
330
     * @param     string $tablename ユーザ情報テーブル名
331
     *
332
     * @return    初期化用SQL
333
     */
334
    private function getSqlDelUser( $tablename )
335
    {
336
        $sql = <<<END_OF_SQL
337
DELETE FROM $tablename
338
 WHERE `userid` = :userid;
339
END_OF_SQL;
340
341
        return $sql;
342
    }
343
344
    /**
345
     * getSqlDelGroup()
346
     *
347
     * グループ情報削除のためのSQLを生成する(Noでの削除用)
348
     *
349
     * @access    private
350
     *
351
     * @param     string $tablename ユーザ情報テーブル名
352
     *
353
     * @return    初期化用SQL
354
     */
355
    private function getSqlDelGroup( $tablename )
356
    {
357
        $sql = <<<END_OF_SQL
358
DELETE FROM $tablename
359
 WHERE `groupid` = :groupid;
360
END_OF_SQL;
361
362
        return $sql;
363
    }
364
365
    /**
366
     * getSqlDelUserGroupByNo()
367
     *
368
     * ユーザ/グループ情報削除のためのSQLを生成する(Noでの削除用)
369
     *
370
     * @access    private
371
     *
372
     * @param     string $tablename ユーザ情報テーブル名
373
     *
374
     * @return    初期化用SQL
375
     */
376
    private function getSqlDelUserGroupByNo( $tablename )
377
    {
378
        $sql = <<<END_OF_SQL
379
DELETE FROM $tablename
380
 WHERE `no` = :no;
381
END_OF_SQL;
382
383
        return $sql;
384
    }
385
386
    /**
387
     * getSqlShowUserAll()
388
     *
389
     * ユーザ情報表示のためのSQLを生成する
390
     *
391
     * @access    private
392
     *
393
     * @param     string $tablename ユーザ情報テーブル名
394
     *
395
     * @return    SQL
396
     */
397
    private function getSqlShowUserAll( $tablename )
398
    {
399
        $sql = <<<END_OF_SQL
400
SELECT
401
       `created_at`
402
     , `created_by`
403
     , `modified_at`
404
     , `modified_by`
405
     , `no`
406
     , `userid`
407
     , `username`
408
     , `password`
409
     , `groupno`
410
     , `status`
411
 FROM $tablename
412
END_OF_SQL;
413
414
        return $sql;
415
    }
416
417
    /**
418
     * getSqlShowGroupAll()
419
     *
420
     * グループ情報表示のためのSQLを生成する
421
     *
422
     * @access    private
423
     *
424
     * @param     string $tablename グループ情報テーブル名
425
     *
426
     * @return    SQL
427
     */
428
    private function getSqlShowGroupAll( $tablename )
429
    {
430
        $sql = <<<END_OF_SQL
431
SELECT
432
       `created_at`
433
     , `created_by`
434
     , `modified_at`
435
     , `modified_by`
436
     , `no`
437
     , `groupid`
438
     , `groupname`
439
     , `status`
440
 FROM $tablename
441
END_OF_SQL;
442
443
        return $sql;
444
    }
445
446
    /**
447
     * getSqlShowUser()
448
     *
449
     * ユーザ情報表示のためのSQLを生成する
450
     *
451
     * @access    private
452
     *
453
     * @param     string $tablename ユーザ情報テーブル名
454
     *
455
     * @return    SQL
456
     */
457
    private function getSqlShowUser( $tablename )
458
    {
459
        $sql = <<<END_OF_SQL
460
SELECT
461
       `created_at`
462
     , `created_by`
463
     , `modified_at`
464
     , `modified_by`
465
     , `no`
466
     , `userid`
467
     , `username`
468
     , `password`
469
     , `groupno`
470
     , `status`
471
 FROM $tablename
472
WHERE `userid` = :userid
473
END_OF_SQL;
474
475
        return $sql;
476
    }
477
478
    /**
479
     * getSqlShowGroup()
480
     *
481
     * グループ情報表示のためのSQLを生成する
482
     *
483
     * @access    private
484
     *
485
     * @param     string $tablename グループ情報テーブル名
486
     *
487
     * @return    SQL
488
     */
489
    private function getSqlShowGroup( $tablename )
490
    {
491
        $sql = <<<END_OF_SQL
492
SELECT
493
       `created_at`
494
     , `created_by`
495
     , `modified_at`
496
     , `modified_by`
497
     , `no`
498
     , `groupid`
499
     , `groupname`
500
     , `status`
501
 FROM $tablename
502
WHERE `groupid` = :groupid
503
END_OF_SQL;
504
505
        return $sql;
506
    }
507
508
    /**
509
     * getSqlShowUserByNo()
510
     *
511
     * Noでのユーザ情報表示のためのSQLを生成する
512
     *
513
     * @access    private
514
     *
515
     * @param     string $tablename グループ情報テーブル名
516
     *
517
     * @return    SQL
518
     */
519
    private function getSqlShowUserByNo( $tablename )
520
    {
521
        $sql = <<<END_OF_SQL
522
SELECT
523
       `created_at`
524
     , `created_by`
525
     , `modified_at`
526
     , `modified_by`
527
     , `no`
528
     , `userid`
529
     , `username`
530
     , `password`
531
     , `groupno`
532
     , `status`
533
 FROM $tablename
534
WHERE `no` = :no
535
END_OF_SQL;
536
537
        return $sql;
538
    }
539
540
    /**
541
     * getSqlShowGroupByNo()
542
     *
543
     * noでのグループ情報表示のためのSQLを生成する
544
     *
545
     * @access    private
546
     *
547
     * @param     string $tablename グループ情報テーブル名
548
     *
549
     * @return    SQL
550
     */
551
    private function getSqlShowGroupByNo( $tablename )
552
    {
553
        $sql = <<<END_OF_SQL
554
SELECT
555
       `created_at`
556
     , `created_by`
557
     , `modified_at`
558
     , `modified_by`
559
     , `no`
560
     , `groupid`
561
     , `groupname`
562
     , `status`
563
 FROM $tablename
564
WHERE `no` = :no
565
END_OF_SQL;
566
567
        return $sql;
568
    }
569
570
    /**
571
     * getParams()
572
     *
573
     * DBアクセス用のパラメタ情報を取得する
574
     *
575
     * @access    private
576
     *
577
     * @param     string $type 識別子
578
     * @param     string $option オプション情報
579
     *
580
     * @return    array パラメタ情報が格納された配列
581
     */
582
    private function getParams( $type, $option )
583
    {
584
        // 識別子に応じて戻す配列を変更する
585
        switch ($type) {
586
            // ユーザ追加/更新向け
587
            case 'UserAddMod':
588
                $retval = [
589
                    [
590
                        'id' => ':by_who',
591
                        'value' => \Risoluto\Text::checkFalseVal( $option[ 'by_who' ], 'Risoluto' ),
592
                        'type' => \PDO::PARAM_STR
593
                    ],
594
                    [ 'id' => ':userid', 'value' => $option[ 'userid' ], 'type' => \PDO::PARAM_STR ],
595
                    [ 'id' => ':username', 'value' => $option[ 'username' ], 'type' => \PDO::PARAM_STR ],
596
                    [ 'id' => ':password', 'value' => $option[ 'password' ], 'type' => \PDO::PARAM_STR ],
597
                    [ 'id' => ':groupno', 'value' => $option[ 'groupno' ], 'type' => \PDO::PARAM_INT ],
598
                    [
599
                        'id' => ':status',
600
                        'value' => \Risoluto\Text::checkFalseVal( $option[ 'status' ], 1, true ),
601
                        'type' => \PDO::PARAM_INT
602
                    ],
603
                ];
604
                break;
605
606
            // グループ追加/更新向け
607
            case 'GroupAddMod':
608
                $retval = [
609
                    [
610
                        'id' => ':by_who',
611
                        'value' => \Risoluto\Text::checkFalseVal( $option[ 'by_who' ], 'Risoluto' ),
612
                        'type' => \PDO::PARAM_STR
613
                    ],
614
                    [ 'id' => ':groupid', 'value' => $option[ 'groupid' ], 'type' => \PDO::PARAM_STR ],
615
                    [ 'id' => ':groupname', 'value' => $option[ 'groupname' ], 'type' => \PDO::PARAM_STR ],
616
                    [
617
                        'id' => ':status',
618
                        'value' => \Risoluto\Text::checkFalseVal( $option[ 'status' ], 1, true ),
619
                        'type' => \PDO::PARAM_INT
620
                    ],
621
                ];
622
                break;
623
624
            // ユーザ更新(No使用)向け
625
            case 'UserModByNo':
626
                $retval = [
627
                    [
628
                        'id' => ':by_who',
629
                        'value' => \Risoluto\Text::checkFalseVal( $option[ 'by_who' ], 'Risoluto' ),
630
                        'type' => \PDO::PARAM_STR
631
                    ],
632
                    [ 'id' => ':no', 'value' => $option[ 'no' ], 'type' => \PDO::PARAM_INT ],
633
                    [ 'id' => ':userid', 'value' => $option[ 'userid' ], 'type' => \PDO::PARAM_STR ],
634
                    [ 'id' => ':username', 'value' => $option[ 'username' ], 'type' => \PDO::PARAM_STR ],
635
                    [ 'id' => ':password', 'value' => $option[ 'password' ], 'type' => \PDO::PARAM_STR ],
636
                    [ 'id' => ':groupno', 'value' => $option[ 'groupno' ], 'type' => \PDO::PARAM_INT ],
637
                    [
638
                        'id' => ':status',
639
                        'value' => \Risoluto\Text::checkFalseVal( $option[ 'status' ], 1, true ),
640
                        'type' => \PDO::PARAM_INT
641
                    ],
642
                ];
643
                break;
644
645
            // グループ更新(No使用)向け
646
            case 'GroupModByNo':
647
                $retval = [
648
                    [
649
                        'id' => ':by_who',
650
                        'value' => \Risoluto\Text::checkFalseVal( $option[ 'by_who' ], 'Risoluto' ),
651
                        'type' => \PDO::PARAM_STR
652
                    ],
653
                    [ 'id' => ':no', 'value' => $option[ 'no' ], 'type' => \PDO::PARAM_INT ],
654
                    [ 'id' => ':groupid', 'value' => $option[ 'groupid' ], 'type' => \PDO::PARAM_STR ],
655
                    [ 'id' => ':groupname', 'value' => $option[ 'groupname' ], 'type' => \PDO::PARAM_STR ],
656
                    [
657
                        'id' => ':status',
658
                        'value' => \Risoluto\Text::checkFalseVal( $option[ 'status' ], 1, true ),
659
                        'type' => \PDO::PARAM_INT
660
                    ],
661
                ];
662
                break;
663
664
            // ユーザIDのみ
665
            case 'UserID':
666
                $retval = [
667
                    [ 'id' => ':userid', 'value' => $option[ 'userid' ], 'type' => \PDO::PARAM_STR ],
668
                ];
669
                break;
670
671
            // グループIDのみ
672
            case 'GroupID':
673
                $retval = [
674
                    [ 'id' => ':groupid', 'value' => $option[ 'groupid' ], 'type' => \PDO::PARAM_STR ],
675
                ];
676
                break;
677
678
            // Noのみ
679
            case 'No':
680
                $retval = [
681
                    [ 'id' => ':no', 'value' => $option[ 'no' ], 'type' => \PDO::PARAM_INT ],
682
                ];
683
                break;
684
685
            // デフォルトの場合は空配列を返す
686
            default:
687
                $retval = [ ];
688
        }
689
690
        return $retval;
691
    }
692
693
    /**
694
     * getInfoFromConf()
695
     *
696
     * コンフィグから認証情報ファイルの情報を取得する
697
     *
698
     * @access    private
699
     *
700
     * @param     void
701
     *
702
     * @return    array 認証情報ファイルの情報
703
     */
704
    private function getInfoFromConf()
705
    {
706
        // コンフィグファイルの読み込み
707
        $conf = new Conf;
708
        $conf->parse( RISOLUTO_CONF . 'risoluto.ini' );
709
710
        // コンフィグファイルの読み込み
711
        $dbconf = new Conf;
712
        $dbconf->parse( RISOLUTO_CONF . 'risoluto_db.ini' );
713
714
        // コンフィグからファイル名情報を取得する
715
        return [
716
            'usertable' => $conf->getIni( "AUTH", "users" ),
717
            'grouptable' => $conf->getIni( "AUTH", "groups" ),
718
            'db' => $dbconf->getIni( "DB" )
719
        ];
720
    }
721
722
    /**
723
     * init()
724
     *
725
     * 認証情報保持テーブルの初期化を行う
726
     *
727
     * @access    public
728
     *
729
     * @param     void
730
     *
731
     * @return    boolean true:成功/false:失敗
732
     */
733
    public function init()
734
    {
735
        // 情報を取得
736
        $info = $this->getInfoFromConf();
737
738
        // DBインスタンスを生成してDBに接続
739
        $retval = true;
740
        $instance = new \Risoluto\Db();
741
        if ($instance->connect( $info[ 'db' ] )) {
742
            if (!$instance->exec( $this->getSqlInitUserTbl( $info[ 'usertable' ] ) )) {
743
                $retval = false;
744
            }
745
746
            if (!$instance->exec( $this->getSqlInitGroupTbl( $info[ 'grouptable' ] ) )) {
747
                $retval = false;
748
            }
749
750
            // DB接続のクローズ
751
            if (!$instance->disConnect( true )) {
752
                $retval = false;
753
            }
754
        } else {
755
            $retval = false;
756
        }
757
758
        return $retval;
759
    }
760
761
    /**
762
     * doAuth($user, $pass, array $option = [])
763
     *
764
     * 認証を行う
765
     *
766
     * @access    public
767
     *
768
     * @param     string $user ユーザID
769
     * @param     string $pass パスワード
770
     * @param     array  $option オプション情報(省略可)
771
     *
772
     * @return    boolean true:認証成功/false:認証失敗
773
     */
774
    public function doAuth( $user, $pass, array $option = [ ] )
775
    {
776
        // ユーザ情報を取得
777
        $get_user = $this->doOperation( 'showUser', [ 'userid' => $user ] );
778
779
        // 複数権取得できた場合や無効なユーザの場合はエラー
780
        if (count( $get_user ) > 1 or $get_user[ 0 ][ 'status' ] != '1') {
781
            return false;
782
        } else {
783
            $auth_user = $get_user[ 0 ];
784
        }
785
786
        // DBから取得したユーザ情報のパスワードと引数で与えられたパスワードを比較する
787
        if (password_verify( $pass, $auth_user[ 'password' ] ) and $auth_user[ 'status' ] == 1) {
788
            return true;
789
        } else {
790
            return false;
791
        }
792
    }
793
794
    /**
795
     * doOperation(array $option = [])
796
     *
797
     * 認証情報操作に関する処理を行う
798
     *
799
     * @access    public
800
     *
801
     * @param     string $operation オペレーション識別子(addUser/addGroup/modUser/modGroup/delUser/delGroup/showUser/showGroup/showUserAll/showGroupAll)
802
     * @param     array  $option オプション情報(省略可)
803
     *
804
     * @return    mixed trueまたは取得内容:成功/false:失敗
805
     */
806
    public function doOperation( $operation, array $option = [ ] )
807
    {
808
        // 情報を取得
809
        $info = $this->getInfoFromConf();
810
811
        // DBインスタンスを生成してDBに接続
812
        $instance = new \Risoluto\Db();
813
        if ($instance->connect( $info[ 'db' ] )) {
814
815
            // オペレーション識別子に応じて処理を行う
816
            switch ($operation) {
817
                case 'addUser':
818
                    $get_data = $instance->doQuery( $this->getSqlAddUser( $info[ 'usertable' ] ),
819
                        $this->getParams( 'UserAddMod', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
820
                    break;
821
822
                case 'addGroup':
823
                    $get_data = $instance->doQuery( $this->getSqlAddGroup( $info[ 'grouptable' ] ),
824
                        $this->getParams( 'GroupAddMod', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
825
                    break;
826
827
                case 'modUser':
828
                    $get_data = $instance->doQuery( $this->getSqlModUser( $info[ 'usertable' ] ),
829
                        $this->getParams( 'UserAddMod', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
830
                    break;
831
832
                case 'modGroup':
833
                    $get_data = $instance->doQuery( $this->getSqlModGroup( $info[ 'grouptable' ] ),
834
                        $this->getParams( 'GroupAddMod', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
835
                    break;
836
837
                case 'modUserByNo':
838
                    $get_data = $instance->doQuery( $this->getSqlModUserByNo( $info[ 'usertable' ] ),
839
                        $this->getParams( 'UserModByNo', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
840
                    break;
841
842
                case 'modGroupByNo':
843
                    $get_data = $instance->doQuery( $this->getSqlModGroupByNo( $info[ 'grouptable' ] ),
844
                        $this->getParams( 'GroupModByNo', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
845
                    break;
846
847
                case 'delUser':
848
                    $get_data = $instance->doQuery( $this->getSqlDelUser( $info[ 'usertable' ] ),
849
                        $this->getParams( 'UserID', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
850
                    break;
851
852
                case 'delGroup':
853
                    $get_data = $instance->doQuery( $this->getSqlDelGroup( $info[ 'grouptable' ] ),
854
                        $this->getParams( 'GroupID', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
855
                    break;
856
857
                case 'delUserByNo':
858
                    $get_data = $instance->doQuery( $this->getSqlDelUserGroupByNo( $info[ 'usertable' ] ),
859
                        $this->getParams( 'No', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
860
                    break;
861
862
                case 'delGroupByNo':
863
                    $get_data = $instance->doQuery( $this->getSqlDelUserGroupByNo( $info[ 'grouptable' ] ),
864
                        $this->getParams( 'No', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
865
                    break;
866
867
                case 'showUser':
868
                    $get_data = $instance->doQuery( $this->getSqlShowUser( $info[ 'usertable' ] ),
869
                        $this->getParams( 'UserID', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
870
                    break;
871
872
                case 'showGroup':
873
                    $get_data = $instance->doQuery( $this->getSqlShowGroup( $info[ 'grouptable' ] ),
874
                        $this->getParams( 'GroupID', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
875
                    break;
876
877
                case 'showUserAll':
878
                    $get_data = $instance->doQuery( $this->getSqlShowUserAll( $info[ 'usertable' ] ) );
879
                    break;
880
881
                case 'showGroupAll':
882
                    $get_data = $instance->doQuery( $this->getSqlShowGroupAll( $info[ 'grouptable' ] ) );
883
                    break;
884
885
                case 'showUserByNo':
886
                    $get_data = $instance->doQuery( $this->getSqlShowUserByNo( $info[ 'usertable' ] ),
887
                        $this->getParams( 'No', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
888
                    break;
889
890
                case 'showGroupByNo':
891
                    $get_data = $instance->doQuery( $this->getSqlShowGroupByNo( $info[ 'grouptable' ] ),
892
                        $this->getParams( 'No', $option ) );
0 ignored issues
show
Documentation introduced by
$option is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
893
                    break;
894
895
                // 未定義の識別子の場合は無条件でfalseを返す
896
                default:
897
                    $get_data = false;
898
            }
899
900
            // 戻り値をチェック
901
            if ($get_data === false) {
902
                $retval = false;
903
            } else {
904
                // 表示系のものについては戻り値がfalseでないものはtrue扱いにする
905
                switch ($operation) {
906
                    case 'showUser':
907
                    case 'showGroup':
908
                    case 'showUserAll':
909
                    case 'showGroupAll':
910
                    case 'showUserByNo':
911
                    case 'showGroupByNo':
912
                        $retval = $get_data;
913
                        break;
914
915
                    default:
916
                        $retval = true;
917
                        break;
918
                }
919
            }
920
921
            // DB接続のクローズ
922
            if (!$instance->disConnect( true )) {
923
                $retval = false;
924
            }
925
        } else {
926
            $retval = false;
927
        }
928
929
        return $retval;
930
    }
931
}
932