Completed
Push — master ( b746e6...94717f )
by Jonathan
06:37
created

SosaListMissingView   B

Complexity

Total Complexity 21

Size/Duplication

Total Lines 188
Duplicated Lines 29.79 %

Coupling/Cohesion

Components 1
Dependencies 17

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 21
lcom 1
cbo 17
dl 56
loc 188
rs 7.8571
c 3
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
D renderContent() 56 181 21

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * webtrees-lib: MyArtJaub library for webtrees
4
 *
5
 * @package MyArtJaub\Webtrees
6
 * @subpackage Sosa
7
 * @author Jonathan Jaubart <[email protected]>
8
 * @copyright Copyright (c) 2009-2016, Jonathan Jaubart
9
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
10
 */
11
namespace MyArtJaub\Webtrees\Module\Sosa\Views;
12
13
use Fisharebest\Webtrees\Date;
14
use Fisharebest\Webtrees\Filter;
15
use Fisharebest\Webtrees\Functions\Functions;
16
use Fisharebest\Webtrees\GedcomTag;
17
use Fisharebest\Webtrees\I18N;
18
use Fisharebest\Webtrees\Individual;
19
use MyArtJaub\Webtrees\Constants;
20
use MyArtJaub\Webtrees\Functions\FunctionsPrint;
21
use MyArtJaub\Webtrees\Functions\FunctionsPrintLists;
22
use MyArtJaub\Webtrees\Module\ModuleManager;
23
24
/**
25
 * View for SosaList@missing
26
 */
27
class SosaListMissingView extends SosaListView {
28
        
29
	/**
30
	 * {@inhericDoc}
31
	 * @see \MyArtJaub\Webtrees\Mvc\View\AbstractView::renderContent()
32
	 */
33
    protected function renderContent() {
34
        ?>
35
            <div id="maj-sosa-missing-page" class="center">
36
    			<h2><?= $this->data->get('title') ?></h2>
37
    			
38
    			<?php  if($this->data->get('is_setup')) { 
39
    			    $this->renderSosaHeader();
40
    			    if($this->data->get('has_missing', false)) {
41
    			        $table_id = $this->data->get('table_id');
42
    			        ?>
43
    			<div id="sosa-indi-missing" class="smissing-list">
44
                	<table id="<?= $table_id ?>">
45
        				<thead>     
46
            				<tr>
47
    							<th colspan="11">
48
    								<div class="btn-toolbar">
49
    									<div class="btn-group">
50
    										<button
51
    											class="ui-state-default"
52
    											data-filter-column="10"
53
    											data-filter-value="M"
54
    											title="<?php I18N::translate('Show only males.'); ?>"
55
    											type="button"
56
    										>
57
    										<?= Individual::sexImage('M', 'large') ?>
58
    										</button>
59
    										<button
60
    											class="ui-state-default"
61
    											data-filter-column="10"
62
    											data-filter-value="F"
63
    											title="<?php I18N::translate('Show only females.'); ?>"
64
    											type="button"
65
    										>
66
    										<?= Individual::sexImage('F', 'large') ?>
67
    										</button>
68
    										<button
69
    											class="ui-state-default"
70
    											data-filter-column="10"
71
    											data-filter-value="U"
72
    											title="<?php I18N::translate('Show only individuals for whom the gender is not known.'); ?>"
73
    											type="button"
74
    										>
75
    										<?= Individual::sexImage('U', 'large') ?>
76
    										</button>
77
    									</div>
78
    								</div>
79
    							</th>
80
    						</tr>       				
81
        					<tr>
82
        						<th><?= I18N::translate('Sosa') ?></th>
83
        						<th><?= GedcomTag::getLabel('INDI') ?></th>
84
        						<th><?= GedcomTag::getLabel('GIVN') ?></th>
85
        						<th><?= GedcomTag::getLabel('SURN') ?></th>
86
        						<?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) { ?>
87
        						<th><i class="icon-source" title="<?= I18N::translate('Sourced individual') ?>" border="0"></i></th>
88
        						<?php } else { ?>
89
        						<th></th>
90
        						<?php } ?>
91
        						<th><?= Functions::getRelationshipNameFromPath('fat') ?></th>
92
								<th><?= Functions::getRelationshipNameFromPath('mot') ?></th>        						
93
        						<th><?= GedcomTag::getLabel('BIRT') ?></th>
94
        						<th><?= GedcomTag::getLabel('PLAC') ?></th>
95
        						<?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) { ?>
96
        						<th><i class="icon-source" title="<?= I18N::translate('Sourced birth') ?>" border="0"></i></th>
97
        						<?php } else { ?>
98
        						<th></th>
99
        						<?php } ?>
100
        						<th hidden>SEX</th>
101
        					</tr>
102
        				</thead>
103
        			<tbody>
104
        			
105
        			<?php foreach($this->data->get('missing_list') as $missing_tab) {
106
        			    $person = $missing_tab['indi'];
107
        			    
108
        			    /** @var \Fisharebest\Webtrees\Individual $person */
109 View Code Duplication
        			    if ($person->isPendingAddtion()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
110
        			        $class = ' class="new"';
111
        			    } elseif ($person->isPendingDeletion()) {
112
        			        $class = ' class="old"';
113
        			    } else {
114
        			        $class = '';
115
        			    }
116
        			    $dperson = new \MyArtJaub\Webtrees\Individual($person);
117
        			    list($surn_givn, $givn_surn) = FunctionsPrintLists::sortableNames($person);
118
        			    ?>			
119
                		<tr <?= $class ?>>
120
                			<td class="transparent"><?= $missing_tab['sosa'] ?></td>
121
                			<td class="transparent"><?= $person->getXref() ?></td>
122
                			<td colspan="2" data-sort="<?= Filter::escapeHtml($givn_surn) ?>">
123 View Code Duplication
                			<?php foreach ($person->getAllNames() as $num=>$name) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
124
                				if ($name['type']=='NAME') {
125
                					$title='';
126
                				} else {
127
                					$title='title="'.strip_tags(GedcomTag::getLabel($name['type'], $person)).'"';
128
                				}
129
                				if ($num==$person->getPrimaryName()) {
130
                					$class=' class="name2"';
131
                					$sex_image=$person->getSexImage();
132
                				} else {
133
                					$class='';
134
                					$sex_image='';
135
                				} ?>
136
                				<a <?= $title.' '.$class ?> href="<?= $person->getHtmlUrl() ?>">
137
                					<?= \Fisharebest\Webtrees\Functions\FunctionsPrint::highlightSearchHits($name['full']) ?>
138
                				</a>
139
                				<?= $sex_image;
140
                				echo implode('&nbsp;',
141
                				    \MyArtJaub\Webtrees\Hook\HookProvider::getInstance()
142
                				    ->get('hRecordNameAppend')
143
                				    ->executeOnlyFor(array(Constants::MODULE_MAJ_SOSA_NAME),  $person, 'smaller'));  ?>
144
                				<br/>
145
                    		<?php }
146
                    		echo $person->getPrimaryParentsNames('parents details1', 'none');
147
                    		?>
148
                    		</td>
149
							<td hidden data-sort="<?= Filter::escapeHtml($surn_givn) ?>"></td>             		
150 View Code Duplication
                			<?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
151
        				        $isISourced = $dperson->isSourced(); ?>
152
        				   	<td data-sort="<?= $isISourced ?>"><?= FunctionsPrint::formatIsSourcedIcon('R', $isISourced, 'INDI', 1, 'medium') ?></td>
0 ignored issues
show
Bug introduced by
It seems like $isISourced defined by $dperson->isSourced() on line 151 can also be of type boolean; however, MyArtJaub\Webtrees\Funct...::formatIsSourcedIcon() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
153
        					<?php } else { ?>
154
        					<td>&nbsp;</td>
155
        					<?php } ?>
156
        					<td><?= $missing_tab['has_father'] ? '&nbsp;' : 'X' ?></td>
157
        					<td><?= $missing_tab['has_mother'] ? '&nbsp;' : 'X' ?></td>
158
                    		<?php $birth_dates = $person->getAllBirthDates(); ?>
159
                    		<td data-sort="<?= $person->getEstimatedBirthDate()->julianDay() ?>">
160
                    		<?php                     		
161
                    		foreach ($birth_dates as $n => $birth_date) {
162
                    		    if ($n > 0) { ?> <br> <?php  } 
163
                    		    echo $birth_date->display(true);
164
                    		}
165
                    		?>
166
                    		</td>
167
                			<td>
168
                			<?php foreach ($person->getAllBirthPlaces() as $n => $birth_place) {
169
        				        $tmp = new \Fisharebest\Webtrees\Place($birth_place, $person->getTree());
170
                				if ($n > 0) { ?><br><?php } ?>
171
                				<a href="'<?= $tmp->getURL(); ?>" title="<?= strip_tags($tmp->getFullName()) ?>">
172
                					<?= \Fisharebest\Webtrees\Functions\FunctionsPrint::highlightSearchHits($tmp->getShortName()) ?>
173
                				</a>
174
                			<?php } ?>
175
                			</td>
176 View Code Duplication
        					<?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
177
        				        $isBSourced = $dperson->isBirthSourced(); ?>
178
        				   	<td data-sort="<?= $isBSourced ?>"><?= FunctionsPrint::formatIsSourcedIcon('E', $isBSourced, 'BIRT', 1, 'medium') ?></td>
0 ignored issues
show
Bug introduced by
It seems like $isBSourced defined by $dperson->isBirthSourced() on line 177 can also be of type boolean; however, MyArtJaub\Webtrees\Funct...::formatIsSourcedIcon() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
179
        					<?php } else { ?>
180
        					<td>&nbsp;</td>
181
        					<?php } ?>
182
        					<td hidden><?= $person->getSex() ?></td>
183
        				</tr>
184
                	<?php } ?>
185
                	</tbody>
186
                	<tfoot>
187
						<tr>
188
							<td class="ui-state-default" colspan="11">
189
								<div class="center">
190
									<?= I18N::translate('Number of different missing ancestors: %s', I18N::number($this->data->get('missing_diff_count'))) ?>
191 View Code Duplication
									<?php if($this->data->get('missing_hidden') > 0) echo ' ['. I18N::translate('%s hidden', I18N::number($this->data->get('missing_hidden'))).']'; ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
192
									<?= ' - ' . I18N::translate('Generation complete at %s', I18N::percentage($this->data->get('perc_sosa'), 2)) ?>
193
									<?= ' [' . I18N::translate('Potential %s', I18N::percentage($this->data->get('perc_sosa_potential'),2)).']' ?>
194
								</div>
195
							</td>
196
						</tr>
197
					</tfoot>
198
                </table>
199
    			 <?php } else if ($this->data->get('generation', 0) > 0) { ?> 
200
    			<p><?= I18N::translate('No ancestors are missing for this generation. Generation complete at %s.', I18N::percentage($this->data->get('perc_sosa'), 2)) ?></p>
201
    			    <?php }   			    
202 View Code Duplication
    			} else { ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
203
    			<p class="warning"><?= I18N::translate('The list could not be displayed. Reasons might be:') ?><br/>
204
    				<ul>
205
    					<li><?= I18N::translate('No Sosa root individual has been defined.') ?></li>
206
    					<li><?= I18N::translate('The Sosa ancestors have not been computed yet.') ?></li>
207
    					<li><?= I18N::translate('No generation were found.') ?></li>
208
    				</ul>
209
    			</p>
210
    			<?php } ?>
211
    		</div> 
212
    		<?php 
213
        }
214
}
215