Intraface_Factory::new_k_TemplateFactory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
crap 2
1
<?php
2
class Intraface_Factory
3
{
4
    protected $config;
5
6
    function __construct($config = null)
7
    {
8
        $this->config = $config;
9
    }
10
11
    function new_k_TemplateFactory($c)
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
12
    {
13
        return new Intraface_TemplateFactory(null);
14
    }
15
16
    function new_MDB2($c)
17
    {
18
        return $this->new_MDB2_Driver_Common($c);
19
    }
20
21
    function new_MDB2_Driver_Common($container)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    {
23
        $db = MDB2::singleton(DB_DSN, array('persistent' => true));
24
        if (PEAR::isError($db)) {
25
            throw new Exception($db->getMessage() . $db->getUserInfo());
26
        }
27
28
        $db->setFetchMode(MDB2_FETCHMODE_ASSOC);
29
        $db->query('SET NAMES utf8');
30
        $res = $db->setCharset('utf8');
31
32
        $db->setOption('debug', MDB2_DEBUG);
33
        $db->setOption('portability', MDB2_PORTABILITY_NONE);
34
35
        if (PEAR::isError($res)) {
36
            throw new Exception($res->getUserInfo());
37
        }
38
39 View Code Duplication
        if ($db->getOption('debug')) {
40
            $db->setOption('log_line_break', "\n\n\n\n\t");
41
42
            $my_debug_handler = new MDB2_Debug_ExplainQueries($db);
43
            $db->setOption('debug_handler', array($my_debug_handler, 'collectInfo'));
44
45
            register_shutdown_function(array($my_debug_handler, 'executeAndExplain'));
46
            register_shutdown_function(array($my_debug_handler, 'dumpInfo'));
47
        }
48
49
        return $db;
50
    }
51
52
    function new_DB_Sql($container)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
    {
54
        $db = new DB_Sql(DB_HOST, DB_USER, DB_PASS, DB_NAME);
55
        $db->query('SET NAMES utf8');
56
        return $db;
57
    }
58
59
    function new_Translation2()
60
    {
61
        // set the parameters to connect to your db
62
        $dbinfo = array(
63
            'hostspec' => DB_HOST,
64
            'database' => DB_NAME,
65
            'phptype'  => 'mysql',
66
            'username' => DB_USER,
67
            'password' => DB_PASS
68
        );
69
70
        if (!defined('LANGUAGE_TABLE_PREFIX')) {
71
            define('LANGUAGE_TABLE_PREFIX', 'core_translation_');
72
        }
73
74
        $params = array(
75
            'langs_avail_table' => LANGUAGE_TABLE_PREFIX.'langs',
76
            'strings_default_table' => LANGUAGE_TABLE_PREFIX.'i18n'
77
        );
78
79
        $translation = Translation2::factory('MDB2', $dbinfo, $params);
80
        //always check for errors. In this examples, error checking is omitted
81
        //to make the example concise.
82
        if (PEAR::isError($translation)) {
83
            throw new Exception('Could not start Translation ' . $translation->getMessage());
84
        }
85
86
        // set the group of strings you want to fetch from
87
        // $translation->setPageID($page_id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
88
89
        // add a Lang decorator to provide a fallback language
90
        // $translation = $translation->getDecorator('Lang');
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
91
        // $translation->setOption('fallbackLang', 'uk');
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
92
        // $translation = $translation->getDecorator('LogMissingTranslation');
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
93
        // $translation->setOption('logger', array(new ErrorHandler_Observer_File(ERROR_LOG), 'update'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
94
        $translation = $translation->getDecorator('DefaultText');
95
96
        // %stringID% will be replaced with the stringID
97
        // %pageID_url% will be replaced with the pageID
98
        // %stringID_url% will replaced with a urlencoded stringID
99
        // %url% will be replaced with the targeted url
100
        //$this->translation->outputString = '%stringID% (%pageID_url%)'; //default: '%stringID%'
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
101
        $translation->outputString = '%stringID%';
102
        $translation->url = '';           //same as default
103
        $translation->emptyPrefix  = '';  //default: empty string
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
104
        $translation->emptyPostfix = '';  //default: empty string
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
105
        return $translation;
106
    }
107
108
    function new_Translation2_Cache()
109
    {
110
        $options = array(
111
            "cacheDir" => PATH_CACHE.'translation/',
112
            "lifeTime" => 3600
113
        );
114
        return new Cache_Lite($options);
115
    }
116
117
    function new_Intraface_Auth($container)
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
118
    {
119
        return new Intraface_Auth(session_id());
120
    }
121
122
    function new_Doctrine_Connection_Common()
123
    {
124
        $connection = Doctrine_Manager::connection(DB_DSN);
125
        $connection->setCharset('utf8');
126
        return $connection;
127
    }
128
129
    function new_Swift_Message($c)
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
130
    {
131
        return Swift_Message::newInstance();
132
    }
133
134
    function new_Swift_Mailer($c)
135
    {
136
        return Swift_Mailer::newInstance($this->new_Swift_Transport($c));
0 ignored issues
show
Unused Code introduced by
The call to Intraface_Factory::new_Swift_Transport() has too many arguments starting with $c.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
137
    }
138
139
    function new_Swift_Transport()
140
    {
141
        return Swift_MailTransport::newInstance();
142
    }
143
144
    function new_Cache_Lite()
145
    {
146
        $options = array(
147
            'cacheDir' => PATH_CACHE,
148
            'lifeTime' => 3600
149
        );
150
151
        return new Cache_Lite($options);
152
    }
153
}
154