Fix class and method names to use camel case

This commit is contained in:
Tautvidas Sipavičius
2016-06-30 15:13:48 +03:00
parent c7fd7b8a32
commit 4a91fae984
5 changed files with 32 additions and 31 deletions

View File

@@ -3,6 +3,7 @@ namespace MailPoet\Config;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
use MailPoet\Models\Newsletter; use MailPoet\Models\Newsletter;
use MailPoet\Util\Helpers;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
@@ -41,7 +42,8 @@ class Migrator {
$_this = $this; $_this = $this;
$migrate = function($model) use($_this) { $migrate = function($model) use($_this) {
dbDelta($_this->$model()); $modelMethod = Helpers::underscoreToCamelCase($model);
dbDelta($_this->$modelMethod());
}; };
array_map($migrate, $this->models); array_map($migrate, $this->models);
@@ -86,7 +88,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function custom_fields() { function customFields() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'name varchar(90) NOT NULL,', 'name varchar(90) NOT NULL,',
@@ -100,7 +102,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function sending_queues() { function sendingQueues() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,', 'newsletter_id mediumint(9) NOT NULL,',
@@ -140,7 +142,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function subscriber_segment() { function subscriberSegment() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'subscriber_id mediumint(9) NOT NULL,', 'subscriber_id mediumint(9) NOT NULL,',
@@ -154,7 +156,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function subscriber_custom_field() { function subscriberCustomField() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'subscriber_id mediumint(9) NOT NULL,', 'subscriber_id mediumint(9) NOT NULL,',
@@ -188,7 +190,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function newsletter_templates() { function newsletterTemplates() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'name varchar(250) NOT NULL,', 'name varchar(250) NOT NULL,',
@@ -203,7 +205,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function newsletter_option_fields() { function newsletterOptionFields() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'name varchar(90) NOT NULL,', 'name varchar(90) NOT NULL,',
@@ -216,7 +218,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function newsletter_option() { function newsletterOption() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,', 'newsletter_id mediumint(9) NOT NULL,',
@@ -230,7 +232,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function newsletter_segment() { function newsletterSegment() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,', 'newsletter_id mediumint(9) NOT NULL,',
@@ -243,7 +245,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function newsletter_links() { function newsletterLinks() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,', 'newsletter_id mediumint(9) NOT NULL,',
@@ -257,7 +259,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function newsletter_posts() { function newsletterPosts() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,', 'newsletter_id mediumint(9) NOT NULL,',
@@ -284,7 +286,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function statistics_newsletters() { function statisticsNewsletters() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,', 'newsletter_id mediumint(9) NOT NULL,',
@@ -296,7 +298,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function statistics_clicks() { function statisticsClicks() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,', 'newsletter_id mediumint(9) NOT NULL,',
@@ -311,7 +313,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function statistics_opens() { function statisticsOpens() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,', 'newsletter_id mediumint(9) NOT NULL,',
@@ -323,7 +325,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function statistics_unsubscribes() { function statisticsUnsubscribes() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'newsletter_id mediumint(9) NOT NULL,', 'newsletter_id mediumint(9) NOT NULL,',
@@ -335,7 +337,7 @@ class Migrator {
return $this->sqlify(__FUNCTION__, $attributes); return $this->sqlify(__FUNCTION__, $attributes);
} }
function statistics_forms() { function statisticsForms() {
$attributes = array( $attributes = array(
'id mediumint(9) NOT NULL AUTO_INCREMENT,', 'id mediumint(9) NOT NULL AUTO_INCREMENT,',
'form_id mediumint(9) NOT NULL,', 'form_id mediumint(9) NOT NULL,',
@@ -348,7 +350,7 @@ class Migrator {
} }
private function sqlify($model, $attributes) { private function sqlify($model, $attributes) {
$table = $this->prefix . $model; $table = $this->prefix . Helpers::camelCaseToUnderscore($model);
$sql = array(); $sql = array();
$sql[] = "CREATE TABLE " . $table . " ("; $sql[] = "CREATE TABLE " . $table . " (";

View File

@@ -9,6 +9,7 @@ use \MailPoet\Models\Segment;
use \MailPoet\Segments\WP; use \MailPoet\Segments\WP;
use \MailPoet\Models\Setting; use \MailPoet\Models\Setting;
use \MailPoet\Settings\Pages; use \MailPoet\Settings\Pages;
use \MailPoet\Util\Helpers;
if(!defined('ABSPATH')) exit; if(!defined('ABSPATH')) exit;
@@ -29,7 +30,8 @@ class Populator {
$_this = $this; $_this = $this;
$populate = function($model) use($_this, $wpdb) { $populate = function($model) use($_this, $wpdb) {
$fields = $_this->$model(); $modelMethod = Helpers::underscoreToCamelCase($model);
$fields = $_this->$modelMethod();
$table = $_this->prefix . $model; $table = $_this->prefix . $model;
array_map(function($field) use ($wpdb, $table) { array_map(function($field) use ($wpdb, $table) {
@@ -126,7 +128,7 @@ class Populator {
} }
} }
function newsletter_option_fields() { private function newsletterOptionFields() {
return array( return array(
array( array(
'name' => 'isScheduled', 'name' => 'isScheduled',
@@ -184,7 +186,7 @@ class Populator {
); );
} }
private function newsletter_templates() { private function newsletterTemplates() {
return array( return array(
(new FranksRoastHouseTemplate(Env::$assets_url))->get(), (new FranksRoastHouseTemplate(Env::$assets_url))->get(),
(new BlankTemplate(Env::$assets_url))->get(), (new BlankTemplate(Env::$assets_url))->get(),
@@ -194,7 +196,8 @@ class Populator {
} }
private function populate($model) { private function populate($model) {
$rows = $this->$model(); $modelMethod = Helpers::underscoreToCamelCase($model);
$rows = $this->$modelMethod();
$table = $this->prefix . $model; $table = $this->prefix . $model;
$_this = $this; $_this = $this;

View File

@@ -30,7 +30,7 @@ class Renderer {
} }
function setupTranslations() { function setupTranslations() {
$this->renderer->addExtension(new Twig\i18n(Env::$plugin_name)); $this->renderer->addExtension(new Twig\I18n(Env::$plugin_name));
} }
function setupFunctions() { function setupFunctions() {

View File

@@ -1,7 +1,7 @@
<?php <?php
namespace MailPoet\Twig; namespace MailPoet\Twig;
class i18n extends \Twig_Extension { class I18n extends \Twig_Extension {
private $_text_domain; private $_text_domain;

View File

@@ -13,7 +13,7 @@
<!-- Final methods don't need final in classes marked as final --> <!-- Final methods don't need final in classes marked as final -->
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/> <rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
<!-- All parameters in function signature should be used within the function --> <!-- All parameters in function signature should be used within the function -->
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/> <!--<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>-->
<!-- Don't use methods that extend and only call the parent method --> <!-- Don't use methods that extend and only call the parent method -->
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/> <rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
@@ -51,12 +51,8 @@
<!-- Nesting level should be kept under 5, not more than 10 --> <!-- Nesting level should be kept under 5, not more than 10 -->
<rule ref="Generic.Metrics.NestingLevel"/> <rule ref="Generic.Metrics.NestingLevel"/>
<!-- Function names should use camelCaps --> <!-- Method names should use camelCaps -->
<rule ref="Generic.NamingConventions.CamelCapsFunctionName"> <rule ref="PSR1.Methods.CamelCapsMethodName"/>
<properties>
<property name="strict" value="false"/>
</properties>
</rule>
<!-- Constants should be all uppercase with underscores separating words --> <!-- Constants should be all uppercase with underscores separating words -->
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/> <rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
@@ -68,7 +64,7 @@
<!-- System keywords should always be lower case --> <!-- System keywords should always be lower case -->
<rule ref="Generic.PHP.LowerCaseKeyword"/> <rule ref="Generic.PHP.LowerCaseKeyword"/>
<!-- Disallow silencing errors with @ --> <!-- Disallow silencing errors with @ -->
<rule ref="Generic.PHP.NoSilencedErrors"/> <!--<rule ref="Generic.PHP.NoSilencedErrors"/>-->
<!-- Disallow indenting with tabs --> <!-- Disallow indenting with tabs -->
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/> <rule ref="Generic.WhiteSpace.DisallowTabIndent"/>