PHP CodeStandard update

- all if/while/for/etc blocks have brackets on same line
- functions have brackets on new line
- no blocks without brackets
- all code starts on col 0 and there are no tab intends anymore

off: came case for classes and class methods
ignore: _ prefix functions (we can't change that anymore)
This commit is contained in:
2018-03-15 17:38:33 +09:00
parent 5226fbcfc3
commit 7d42256a30
42 changed files with 11623 additions and 12013 deletions
+104 -102
View File
@@ -73,10 +73,12 @@ class ProgressBar
public function __construct($width = 0, $height = 0)
{
$this->code = substr(md5(microtime()), 0, 6);
if ($width > 0)
if ($width > 0) {
$this->width = $width;
if ($height > 0)
}
if ($height > 0) {
$this->height = $height;
}
// needs to be called twice or I do not get any output
$this->_flushCache($this->clear_buffer_size_init);
$this->_flushCache($this->clear_buffer_size_init);
@@ -86,8 +88,9 @@ class ProgressBar
private function _flushCache($clear_buffer_size = 0)
{
if (!$clear_buffer_size)
if (!$clear_buffer_size) {
$clear_buffer_size = $this->clear_buffer_size;
}
echo str_repeat(' ', $clear_buffer_size);
ob_flush();
flush();
@@ -96,18 +99,19 @@ class ProgressBar
private function _calculatePercent($step)
{
// avoid divison through 0
if ($this->max - $this->min == 0)
if ($this->max - $this->min == 0) {
$this->max ++;
}
$percent = round(($step - $this->min) / ($this->max - $this->min) * 100);
if ($percent > 100)
if ($percent > 100) {
$percent = 100;
}
return $percent;
}
private function _calculatePosition($step)
{
switch ($this->direction)
{
switch ($this->direction) {
case 'right':
case 'left':
$bar = $this->width;
@@ -118,16 +122,18 @@ class ProgressBar
break;
}
// avoid divison through 0
if ($this->max - $this->min == 0)
if ($this->max - $this->min == 0) {
$this->max ++;
}
$pixel = round(($step - $this->min) * ($bar - ($this->pedding * 2)) / ($this->max - $this->min));
if ($step <= $this->min)
if ($step <= $this->min) {
$pixel = 0;
if ($step >= $this->max)
}
if ($step >= $this->max) {
$pixel = $bar - ($this->pedding * 2);
}
switch ($this->direction)
{
switch ($this->direction) {
case 'right':
$position['left'] = $this->pedding;
$position['top'] = $this->pedding;
@@ -158,10 +164,12 @@ class ProgressBar
private function _setStep($step)
{
if ($step > $this->max)
if ($step > $this->max) {
$step = $this->max;
if ($step < $this->min)
}
if ($step < $this->min) {
$step = $this->min;
}
$this->step = $step;
}
@@ -179,16 +187,17 @@ class ProgressBar
'brd_color' => '#dfdfdf #404040 #404040 #dfdfdf'
);
if ($width > 0)
if ($width > 0) {
$this->frame['width'] = $width;
if ($height > 0)
}
if ($height > 0) {
$this->frame['height'] = $height;
}
}
public function addLabel($type, $name, $value = '&nbsp;')
{
switch($type)
{
switch ($type) {
case 'text':
$this->label[$name] = array(
'type' => 'text',
@@ -242,10 +251,11 @@ class ProgressBar
case 'percentlbl':
case 'percent':
// check font size
if ($this->height <= 11)
if ($this->height <= 11) {
$font_size = $this->height - 1;
else
} else {
$font_size = 11;
}
$this->label[$name] = array(
'type' => $type, // either percent or percentlbl
'value' => $value,
@@ -288,23 +298,23 @@ class ProgressBar
$this->label[$name]['target'] = $target;
}
public function setLabelPosition($name, $left, $top, $width, $height, $align='')
public function setLabelPosition($name, $left, $top, $width, $height, $align = '')
{
// print "SET POSITION[$name]: $left<br>";
// if this is percent, we ignore anything, it is auto positioned
if ($this->label[$name]['type'] != 'percent')
{
foreach (array('top', 'left', 'width', 'height') as $pos_name)
if ($$pos_name !== false)
if ($this->label[$name]['type'] != 'percent') {
foreach (array('top', 'left', 'width', 'height') as $pos_name) {
if ($$pos_name !== false) {
$this->label[$name][$pos_name] = intval($$pos_name);
}
}
if ($align != '')
if ($align != '') {
$this->label[$name]['align'] = $align;
}
}
// init
if ($this->status != 'new')
{
if ($this->status != 'new') {
$output = '<script type="text/JavaScript">';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.top="'.$this->label[$name]['top'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.left="'.$this->label[$name]['left'].'px";';
@@ -320,8 +330,7 @@ class ProgressBar
public function setLabelColor($name, $color)
{
$this->label[$name]['color'] = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.color="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -330,8 +339,7 @@ class ProgressBar
public function setLabelBackground($name, $color)
{
$this->label[$name]['bgr_color'] = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.background="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -340,24 +348,28 @@ class ProgressBar
public function setLabelFont($name, $size, $family = '', $weight = '')
{
// just in case if it is too small
if (intval($size) < 0)
if (intval($size) < 0) {
$size = 11;
}
// if this is percent, the size is not allowed to be bigger than the bar size - 5px
if ($this->label[$name]['type'] == 'percent' && intval($size) >= $this->height)
if ($this->label[$name]['type'] == 'percent' && intval($size) >= $this->height) {
$size = $this->height - 1;
}
// position the label new if this is percent
if ($this->label[$name]['type'] == 'percent')
if ($this->label[$name]['type'] == 'percent') {
$this->label[$name]['top'] = round(($this->height - intval($size)) / log($this->height - intval($size), 7), 0) - $this->pedding;
}
// print "HEIGHT: ".$this->height.", Size: ".intval($size).", Pedding: ".$this->pedding.", Calc: ".round($this->height - intval($size)).", Log: ".log($this->height - intval($size), 7)."<br>";
// then set like usual
$this->label[$name]['font-size'] = intval($size);
if ($family != '')
if ($family != '') {
$this->label[$name]['font-family'] = $family;
if ($weight != '')
}
if ($weight != '') {
$this->label[$name]['font-weight'] = $weight;
}
if ($this->status != 'new')
{
if ($this->status != 'new') {
$output = '<script type="text/JavaScript">';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-size="'.$this->label[$name]['font-size'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-family="'.$this->label[$name]['font-family'].'";';
@@ -372,8 +384,7 @@ class ProgressBar
{
$this->label[$name]['value'] = $value;
// print "NAME[$name], Status: ".$this->status.": ".$value."<Br>";
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">PBlabelText'.$this->code.'("'.$name.'","'.$this->label[$name]['value'].'");</script>'."\n";
$this->_flushCache();
}
@@ -382,8 +393,7 @@ class ProgressBar
public function setBarColor($color)
{
$this->color = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("pbar'.$this->code.'").style.background="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -392,8 +402,7 @@ class ProgressBar
public function setBarBackground($color)
{
$this->bgr_color = $color;
if ($this->status != 'new')
{
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("pbrd'.$this->code.'").style.background="'.$color.'";</script>'."\n";
$this->_flushCache();
}
@@ -403,8 +412,7 @@ class ProgressBar
{
$this->direction = $direction;
if ($this->status != 'new')
{
if ($this->status != 'new') {
$this->position = $this->_calculatePosition($this->step);
echo '<script type="text/JavaScript">';
@@ -426,25 +434,30 @@ class ProgressBar
$this->_setStep($this->step);
$this->position = $this->_calculatePosition($this->step);
if ($this->top || $this->left)
if ($this->top || $this->left) {
$style_master = 'position:relative;top:'.$this->top.'px;left:'.$this->left.'px;width:'.($this->width + 10).'px;';
}
$html = '<div id="pbm'.$this->code.'" style="'.$style_master.'background:'.$this->bgr_color_master.';">';
$style_brd = 'width:'.$this->width.'px;height:'.$this->height.'px;background:'.$this->bgr_color.';';
if ($this->border > 0)
if ($this->border > 0) {
$style_brd .= 'border:'.$this->border.'px solid; border-color:'.$this->brd_color.'; -webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px; -webkit-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset;';
}
$style_bar = 'position:relative;width:'.$this->position['width'].'px;height:'.$this->position['height'].'px;background:'.$this->color.';';
if ($this->position['top'] !== false)
if ($this->position['top'] !== false) {
$style_bar .= 'top:'.$this->position['top'].'px;';
if ($this->position['left'] !== false)
}
if ($this->position['left'] !== false) {
$style_bar .= 'left:'.$this->position['left'].'px;';
if ($this->border > 0)
}
if ($this->border > 0) {
$style_bar .= '-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px; -webkit-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset;';
}
if ($this->frame['show'] == true)
{
if ($this->frame['border'] > 0)
if ($this->frame['show'] == true) {
if ($this->frame['border'] > 0) {
$border = 'border:'.$this->frame['border'].'px solid;border-color:'.$this->frame['brd_color'].';margin-top:2px;-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px;';
}
$html .= '<div id="pfrm'.$this->code.'" style="width:'.$this->frame['width'].'px;height:'.$this->frame['height'].'px;'.$border.'background:'.$this->frame['color'].';">'."\n";
}
@@ -465,34 +478,39 @@ class ProgressBar
$js .= '}'."\n";
//print "DUMP LABEL: <br><pre>".print_r($this->label, 1)."</pre><br>";
foreach ($this->label as $name => $data)
{
foreach ($this->label as $name => $data) {
// set what type of move we do
$move_prefix = $data['type'] == 'button' ? 'margin' : 'padding';
$style_lbl = 'position:relative;';
if ($data['top'] !== false)
if ($data['top'] !== false) {
$style_lbl .= $move_prefix.'-top:'.$data['top'].'px;';
if ($data['left'] !== false)
}
if ($data['left'] !== false) {
$style_lbl .= $move_prefix.'-left:'.$data['left'].'px;';
}
$style_lbl .= 'text-align:'.$data['align'].';';
if ($data['width'] > 0)
if ($data['width'] > 0) {
$style_lbl .= 'width:'.$data['width'].'px;';
if ($data['height'] > 0)
}
if ($data['height'] > 0) {
$style_lbl .= 'height:'.$data['height'].'px;';
}
if (array_key_exists('font-size', $data))
if (array_key_exists('font-size', $data)) {
$style_lbl .= 'font-size:'.$data['font-size'].'px;';
if (array_key_exists('font-family', $data))
}
if (array_key_exists('font-family', $data)) {
$style_lbl .= 'font-family:'.$data['font-family'].';';
if (array_key_exists('font-weight', $data))
}
if (array_key_exists('font-weight', $data)) {
$style_lbl .= 'font-weight:'.$data['font-weight'].';';
if (array_key_exists('bgr_color', $data) && ($data['bgr_color'] != ''))
}
if (array_key_exists('bgr_color', $data) && ($data['bgr_color'] != '')) {
$style_lbl .= 'background:'.$data['bgr_color'].';';
}
if (array_key_exists('type', $data))
{
switch ($data['type'])
{
if (array_key_exists('type', $data)) {
switch ($data['type']) {
case 'text':
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'margin-bottom:2px;">'.$data['value'].'</div>'."\n";
break;
@@ -505,8 +523,9 @@ class ProgressBar
case 'percent':
// only one inner percent
// print "STYLE[$name]: ".$style_lbl."<br>";
if (!$html_percent)
if (!$html_percent) {
$html_percent = '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'width:'.$data['width'].'px;line-height:1;text-shadow: 0 0 .2em white, 0 0 .5em white;">'.$this->_calculatePercent($this->step).'%</div>'."\n";
}
break;
case 'percentlbl':
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'width:'.$data['width'].'px;">'.$this->_calculatePercent($this->step).'%</div>'."\n";
@@ -535,17 +554,14 @@ class ProgressBar
$html .= $html_bar_bottom;
$html .= $html_button; // any buttons on bottom
if (count($this->label) > 0)
{
if (count($this->label) > 0) {
$js .= 'function PBlabelText'.$this->code.'(name,text) {'."\n";
$js .= ' name = "plbl" + name + "'.$this->code.'";'."\n";
$js .= ' document.getElementById(name).innerHTML=text;'."\n";
$js .= '}'."\n";
}
if ($this->frame['show'] == true)
{
if ($this->frame['show'] == true) {
$html .= '</div>'."\n";
}
@@ -572,40 +588,31 @@ class ProgressBar
$js = '';
$new_position = $this->_calculatePosition($this->step);
if ($new_position['width'] != $this->position['width'] && ($this->direction == 'right' || $this->direction == 'left'))
{
if ($this->direction=='left')
{
if ($new_position['width'] != $this->position['width'] && ($this->direction == 'right' || $this->direction == 'left')) {
if ($this->direction=='left') {
$js .= 'PBposition'.$this->code.'("left",'.$new_position['left'].');';
}
$js .= 'PBposition'.$this->code.'("width",'.$new_position['width'].');';
}
if ($new_position['height'] != $this->position['height'] && ($this->direction == 'up' || $this->direction == 'down'))
{
if ($this->direction=='up')
{
if ($new_position['height'] != $this->position['height'] && ($this->direction == 'up' || $this->direction == 'down')) {
if ($this->direction=='up') {
$js .= 'PBposition'.$this->code.'("top",'.$new_position['top'].');';
}
$js .= 'PBposition'.$this->code.'("height",'.$new_position['height'].');';
}
$this->position = $new_position;
foreach($this->label as $name => $data)
{
if (array_key_exists('type', $data))
{
switch($data['type'])
{
foreach ($this->label as $name => $data) {
if (array_key_exists('type', $data)) {
switch($data['type']) {
case 'step':
if ($this->step != $last_step)
{
if ($this->step != $last_step) {
$js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$this->step.'/'.$this->max.'");';
}
break;
case 'percentlbl':
case 'percent':
$percent = $this->_calculatePercent($this->step);
if ($percent != $this->_calculatePercent($last_step))
{
if ($percent != $this->_calculatePercent($last_step)) {
$js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$percent.'%");';
}
break;
@@ -615,8 +622,7 @@ class ProgressBar
}
}
}
if ($js != '')
{
if ($js != '') {
echo '<script type="text/JavaScript">'.$js.'</script>'."\n";
$this->_flushCache();
}
@@ -634,8 +640,7 @@ class ProgressBar
public function hide()
{
if ($this->status == 'show')
{
if ($this->status == 'show') {
$this->status = 'hide';
$output = '<script type="text/JavaScript">';
@@ -648,8 +653,7 @@ class ProgressBar
public function unhide()
{
if ($this->status == 'hide')
{
if ($this->status == 'hide') {
$this->status = 'show';
$output = '<script type="text/JavaScript">';
@@ -659,6 +663,4 @@ class ProgressBar
$this->_flushCache();
}
}
}
?>