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 |
||
| 31 | class AlumnoRepository extends EntityRepository |
||
| 32 | { |
||
| 33 | public function findConPartesAunNoNotificados() |
||
| 44 | |||
| 45 | View Code Duplication | public function findConPartesAunNoNotificadosPorUsuario(Usuario $usuario) |
|
| 46 | { |
||
| 47 | $orX = $this->getEntityManager()->createQueryBuilder() |
||
| 48 | ->expr()->orX() |
||
| 49 | ->add('p.usuario = :usuario') |
||
| 50 | ->add('a.grupo = :grupo'); |
||
| 51 | |||
| 52 | return $this->findConPartesAunNoNotificados() |
||
| 53 | ->innerJoin('AppBundle:Grupo', 'g', 'WITH', 'a.grupo = g') |
||
| 54 | ->andWhere($orX) |
||
| 55 | ->setParameter('grupo', $usuario->getTutoria()) |
||
| 56 | ->setParameter('usuario', $usuario); |
||
| 57 | } |
||
| 58 | |||
| 59 | public function findAllConPartesAunNoNotificados() |
||
| 60 | { |
||
| 61 | return $this->findConPartesAunNoNotificados() |
||
| 62 | ->getQuery() |
||
| 63 | ->getResult(); |
||
| 64 | } |
||
| 65 | |||
| 66 | public function findAllConPartesAunNoNotificadosPorUsuario(Usuario $usuario) |
||
| 72 | |||
| 73 | public function findAllConPartesPendientesSancion() |
||
| 74 | { |
||
| 75 | return $this->getEntityManager() |
||
| 76 | ->getRepository('AppBundle:Parte') |
||
| 77 | ->createQueryBuilder('p') |
||
| 78 | ->select('a') |
||
| 79 | ->addSelect('COUNT(p.id)') |
||
| 80 | ->addSelect('MIN(p.fechaSuceso)') |
||
| 81 | ->addSelect('MAX(p.fechaSuceso)') |
||
| 82 | ->addSelect('SUM(p.prioritario)') |
||
| 83 | ->innerJoin('AppBundle:Alumno', 'a') |
||
| 84 | ->where('p.fechaAviso IS NOT NULL') |
||
| 85 | ->andWhere('p.sancion IS NULL') |
||
| 86 | ->andWhere('p.alumno = a') |
||
| 87 | ->andWhere('p.prescrito = false') |
||
| 88 | ->groupBy('a.id') |
||
| 89 | ->orderBy('a.apellido1', 'ASC') |
||
| 90 | ->addOrderBy('a.apellido2', 'ASC') |
||
| 91 | ->addOrderBy('a.nombre', 'ASC') |
||
| 92 | ->getQuery() |
||
| 93 | ->getResult(); |
||
| 94 | } |
||
| 95 | |||
| 96 | public function findConSancionesAunNoNotificadas() |
||
| 111 | |||
| 112 | public function findAllConSancionesAunNoNotificadas() |
||
| 118 | |||
| 119 | public function findAllConSancionesAunNoNotificadasPorTutoria($usuario) |
||
| 128 | |||
| 129 | public function getResumenConvivencia($tutor, $fechas) |
||
| 156 | |||
| 157 | public function getSancionadosPorFecha($fechas) |
||
| 190 | } |
||
| 191 |