GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Cackle::reviews()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 2
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Alexey Tatarinov <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2014 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 * @package 
8
 */
9
Yii::import('ext.cackle.models.*');
10
Yii::import('ext.cackle.*');
11
12
class Cackle extends CApplicationComponent
13
{
14
  protected $siteId;
15
16
  protected $siteApiKey;
17
18
  protected $singleSignOn = false;
19
20 View Code Duplication
  public function init()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
  {
22
    parent::init();
23
24
    $configPath = Yii::getPathOfAlias('frontend.config.cackle').'.php';
25
    if( file_exists($configPath) )
26
    {
27
      $config = require($configPath);
28
      $this->siteId = $config['siteId'];
29
      $this->siteApiKey = $config['siteApiKey'];
30
31
      if( isset($config['singleSignOn']) )
32
        $this->singleSignOn = $config['singleSignOn'];
33
    }
34
    else
35
    {
36
      throw new CHttpException('500', 'Не найден кофигурационный файл cackle.php в папке config');
37
    }
38
  }
39
40
  /**
41
   * @param CActiveRecord|string $channel
42
   * @param null $containerId
43
   */
44 View Code Duplication
  public function comments($channel, $containerId = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
  {
46
    Yii::app()->controller->widget('CackleWidget', array(
47
      'widget' => CackleWidget::COMMENT,
48
      'siteId' => $this->siteId,
49
      'channel' => $channel,
50
      'container' => $containerId,
51
      'ssoAuth' => $this->singleSignOn ? $this->getSingleSignOnString() : '',
52
    ));
53
  }
54
55
  /**
56
   * @param $channel
57
   * @param null $containerId
58
   */
59 View Code Duplication
  public function reviews($channel, $containerId = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
  {
61
    Yii::app()->controller->widget('CackleWidget', array(
62
      'widget' => CackleWidget::REVIEW,
63
      'siteId' => $this->siteId,
64
      'channel' => $channel,
65
      'container' => $containerId,
66
      'ssoAuth' => $this->singleSignOn ? $this->getSingleSignOnString() : array()
67
    ));
68
  }
69
70
  protected function getSingleSignOnString()
71
  {
72
    $user = array();
73
74
    if( !Yii::app()->user->isGuest )
75
    {
76
      /**
77
       * @link http://admin.cackle.me/help/integrating-sso
78
       */
79
      $user = array(
80
        'id' => Yii::app()->user->data->id,
81
        'name' => Yii::app()->user->profile->name,
82
        'email' => Yii::app()->user->getEmail(),
83
        'avatar' => Yii::app()->createAbsoluteUrl('userProfile/avatar', array('id' => Yii::app()->user->data->id)),
84
      );
85
    }
86
    $currentTime = time();
87
88
    $singleSignOn = array();
89
    $singleSignOn['userData'] = base64_encode(!empty($user) ? json_encode($user) : '{}');
90
    $singleSignOn['sign'] = md5($singleSignOn['userData'].$this->siteApiKey.$currentTime);
91
    $singleSignOn['timestamp'] = $currentTime;
92
93
    return implode(' ', $singleSignOn);
94
  }
95
96
  protected function setSiteId($siteId)
97
  {
98
    $this->siteId = $siteId;
99
  }
100
}