| Conditions | 11 | 
| Paths | 11 | 
| Total Lines | 272 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php | ||
| 216 | public function canDeleteLanguage($id) | ||
| 217 |     { | ||
| 218 | $query = $this->dbHandler->createSelectQuery(); | ||
| 219 | $query->select( | ||
| 220 |             $query->alias($query->expr->count('*'), 'count') | ||
| 221 | )->from( | ||
| 222 |             $this->dbHandler->quoteTable('ezcobj_state') | ||
| 223 | )->where( | ||
| 224 | $query->expr->lOr( | ||
| 225 | $query->expr->eq( | ||
| 226 |                     $this->dbHandler->quoteColumn('default_language_id'), | ||
| 227 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 228 | ), | ||
| 229 | $query->expr->gt( | ||
| 230 | $query->expr->bitAnd( | ||
| 231 |                         $this->dbHandler->quoteColumn('language_mask'), | ||
| 232 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 233 | ), | ||
| 234 | 0 | ||
| 235 | ) | ||
| 236 | ) | ||
| 237 | ); | ||
| 238 | |||
| 239 | $statement = $query->prepare(); | ||
| 240 | $statement->execute(); | ||
| 241 | |||
| 242 |         if ($statement->fetchColumn() > 0) { | ||
| 243 | return false; | ||
| 244 | } | ||
| 245 | |||
| 246 | $query = $this->dbHandler->createSelectQuery(); | ||
| 247 | $query->select( | ||
| 248 |             $query->alias($query->expr->count('*'), 'count') | ||
| 249 | )->from( | ||
| 250 |             $this->dbHandler->quoteTable('ezcobj_state_group') | ||
| 251 | )->where( | ||
| 252 | $query->expr->lOr( | ||
| 253 | $query->expr->eq( | ||
| 254 |                     $this->dbHandler->quoteColumn('default_language_id'), | ||
| 255 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 256 | ), | ||
| 257 | $query->expr->gt( | ||
| 258 | $query->expr->bitAnd( | ||
| 259 |                         $this->dbHandler->quoteColumn('language_mask'), | ||
| 260 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 261 | ), | ||
| 262 | 0 | ||
| 263 | ) | ||
| 264 | ) | ||
| 265 | ); | ||
| 266 | |||
| 267 | $statement = $query->prepare(); | ||
| 268 | $statement->execute(); | ||
| 269 | |||
| 270 |         if ($statement->fetchColumn() > 0) { | ||
| 271 | return false; | ||
| 272 | } | ||
| 273 | |||
| 274 | $query = $this->dbHandler->createSelectQuery(); | ||
| 275 | $query->select( | ||
| 276 |             $query->alias($query->expr->count('*'), 'count') | ||
| 277 | )->from( | ||
| 278 |             $this->dbHandler->quoteTable('ezcobj_state_group_language') | ||
| 279 | )->where( | ||
| 280 | $query->expr->gt( | ||
| 281 | $query->expr->bitAnd( | ||
| 282 |                     $this->dbHandler->quoteColumn('language_id'), | ||
| 283 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 284 | ), | ||
| 285 | 0 | ||
| 286 | ) | ||
| 287 | ); | ||
| 288 | |||
| 289 | $statement = $query->prepare(); | ||
| 290 | $statement->execute(); | ||
| 291 | |||
| 292 |         if ($statement->fetchColumn() > 0) { | ||
| 293 | return false; | ||
| 294 | } | ||
| 295 | |||
| 296 | $query = $this->dbHandler->createSelectQuery(); | ||
| 297 | $query->select( | ||
| 298 |             $query->alias($query->expr->count('*'), 'count') | ||
| 299 | )->from( | ||
| 300 |             $this->dbHandler->quoteTable('ezcobj_state_language') | ||
| 301 | )->where( | ||
| 302 | $query->expr->gt( | ||
| 303 | $query->expr->bitAnd( | ||
| 304 |                     $this->dbHandler->quoteColumn('language_id'), | ||
| 305 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 306 | ), | ||
| 307 | 0 | ||
| 308 | ) | ||
| 309 | ); | ||
| 310 | |||
| 311 | $statement = $query->prepare(); | ||
| 312 | $statement->execute(); | ||
| 313 | |||
| 314 |         if ($statement->fetchColumn() > 0) { | ||
| 315 | return false; | ||
| 316 | } | ||
| 317 | |||
| 318 | $query = $this->dbHandler->createSelectQuery(); | ||
| 319 | $query->select( | ||
| 320 |             $query->alias($query->expr->count('*'), 'count') | ||
| 321 | )->from( | ||
| 322 |             $this->dbHandler->quoteTable('ezcontentclass') | ||
| 323 | )->where( | ||
| 324 | $query->expr->lOr( | ||
| 325 | $query->expr->eq( | ||
| 326 |                     $this->dbHandler->quoteColumn('initial_language_id'), | ||
| 327 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 328 | ), | ||
| 329 | $query->expr->gt( | ||
| 330 | $query->expr->bitAnd( | ||
| 331 |                         $this->dbHandler->quoteColumn('language_mask'), | ||
| 332 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 333 | ), | ||
| 334 | 0 | ||
| 335 | ) | ||
| 336 | ) | ||
| 337 | ); | ||
| 338 | |||
| 339 | $statement = $query->prepare(); | ||
| 340 | $statement->execute(); | ||
| 341 | |||
| 342 |         if ($statement->fetchColumn() > 0) { | ||
| 343 | return false; | ||
| 344 | } | ||
| 345 | |||
| 346 | $query = $this->dbHandler->createSelectQuery(); | ||
| 347 | $query->select( | ||
| 348 |             $query->alias($query->expr->count('*'), 'count') | ||
| 349 | )->from( | ||
| 350 |             $this->dbHandler->quoteTable('ezcontentclass_name') | ||
| 351 | )->where( | ||
| 352 | $query->expr->gt( | ||
| 353 | $query->expr->bitAnd( | ||
| 354 |                     $this->dbHandler->quoteColumn('language_id'), | ||
| 355 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 356 | ), | ||
| 357 | 0 | ||
| 358 | ) | ||
| 359 | ); | ||
| 360 | |||
| 361 | $statement = $query->prepare(); | ||
| 362 | $statement->execute(); | ||
| 363 | |||
| 364 |         if ($statement->fetchColumn() > 0) { | ||
| 365 | return false; | ||
| 366 | } | ||
| 367 | |||
| 368 | $query = $this->dbHandler->createSelectQuery(); | ||
| 369 | $query->select( | ||
| 370 |             $query->alias($query->expr->count('*'), 'count') | ||
| 371 | )->from( | ||
| 372 |             $this->dbHandler->quoteTable('ezcontentobject') | ||
| 373 | )->where( | ||
| 374 | $query->expr->lOr( | ||
| 375 | $query->expr->eq( | ||
| 376 |                     $this->dbHandler->quoteColumn('initial_language_id'), | ||
| 377 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 378 | ), | ||
| 379 | $query->expr->gt( | ||
| 380 | $query->expr->bitAnd( | ||
| 381 |                         $this->dbHandler->quoteColumn('language_mask'), | ||
| 382 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 383 | ), | ||
| 384 | 0 | ||
| 385 | ) | ||
| 386 | ) | ||
| 387 | ); | ||
| 388 | |||
| 389 | $statement = $query->prepare(); | ||
| 390 | $statement->execute(); | ||
| 391 | |||
| 392 |         if ($statement->fetchColumn() > 0) { | ||
| 393 | return false; | ||
| 394 | } | ||
| 395 | |||
| 396 | $query = $this->dbHandler->createSelectQuery(); | ||
| 397 | $query->select( | ||
| 398 |             $query->alias($query->expr->count('*'), 'count') | ||
| 399 | )->from( | ||
| 400 |             $this->dbHandler->quoteTable('ezcontentobject_attribute') | ||
| 401 | )->where( | ||
| 402 | $query->expr->gt( | ||
| 403 | $query->expr->bitAnd( | ||
| 404 |                     $this->dbHandler->quoteColumn('language_id'), | ||
| 405 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 406 | ), | ||
| 407 | 0 | ||
| 408 | ) | ||
| 409 | ); | ||
| 410 | |||
| 411 | $statement = $query->prepare(); | ||
| 412 | $statement->execute(); | ||
| 413 | |||
| 414 |         if ($statement->fetchColumn() > 0) { | ||
| 415 | return false; | ||
| 416 | } | ||
| 417 | |||
| 418 | $query = $this->dbHandler->createSelectQuery(); | ||
| 419 | $query->select( | ||
| 420 |             $query->alias($query->expr->count('*'), 'count') | ||
| 421 | )->from( | ||
| 422 |             $this->dbHandler->quoteTable('ezcontentobject_name') | ||
| 423 | )->where( | ||
| 424 | $query->expr->gt( | ||
| 425 | $query->expr->bitAnd( | ||
| 426 |                     $this->dbHandler->quoteColumn('language_id'), | ||
| 427 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 428 | ), | ||
| 429 | 0 | ||
| 430 | ) | ||
| 431 | ); | ||
| 432 | |||
| 433 | $statement = $query->prepare(); | ||
| 434 | $statement->execute(); | ||
| 435 | |||
| 436 |         if ($statement->fetchColumn() > 0) { | ||
| 437 | return false; | ||
| 438 | } | ||
| 439 | |||
| 440 | $query = $this->dbHandler->createSelectQuery(); | ||
| 441 | $query->select( | ||
| 442 |             $query->alias($query->expr->count('*'), 'count') | ||
| 443 | )->from( | ||
| 444 |             $this->dbHandler->quoteTable('ezcontentobject_version') | ||
| 445 | )->where( | ||
| 446 | $query->expr->lOr( | ||
| 447 | $query->expr->eq( | ||
| 448 |                     $this->dbHandler->quoteColumn('initial_language_id'), | ||
| 449 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 450 | ), | ||
| 451 | $query->expr->gt( | ||
| 452 | $query->expr->bitAnd( | ||
| 453 |                         $this->dbHandler->quoteColumn('language_mask'), | ||
| 454 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 455 | ), | ||
| 456 | 0 | ||
| 457 | ) | ||
| 458 | ) | ||
| 459 | ); | ||
| 460 | |||
| 461 | $statement = $query->prepare(); | ||
| 462 | $statement->execute(); | ||
| 463 | |||
| 464 |         if ($statement->fetchColumn() > 0) { | ||
| 465 | return false; | ||
| 466 | } | ||
| 467 | |||
| 468 | $query = $this->dbHandler->createSelectQuery(); | ||
| 469 | $query->select( | ||
| 470 |             $query->alias($query->expr->count('*'), 'count') | ||
| 471 | )->from( | ||
| 472 |             $this->dbHandler->quoteTable('ezurlalias_ml') | ||
| 473 | )->where( | ||
| 474 | $query->expr->gt( | ||
| 475 | $query->expr->bitAnd( | ||
| 476 |                     $this->dbHandler->quoteColumn('lang_mask'), | ||
| 477 | $query->bindValue($id, null, \PDO::PARAM_INT) | ||
| 478 | ), | ||
| 479 | 0 | ||
| 480 | ) | ||
| 481 | ); | ||
| 482 | |||
| 483 | $statement = $query->prepare(); | ||
| 484 | $statement->execute(); | ||
| 485 | |||
| 486 | return $statement->fetchColumn() == 0; | ||
| 487 | } | ||
| 488 | } | ||
| 489 | 
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: